مَا كَانَ لِاَهْلِ الْمَدِيْنَةِ وَمَنْ حَوْلَهُمْ مِّنَ الْاَعْرَابِ اَنْ يَّتَخَلَّفُوْا عَنْ رَّسُوْلِ اللّٰهِ وَلَا يَرْغَبُوْا بِاَنْفُسِهِمْ عَنْ نَّفْسِهٖۗ ذٰلِكَ بِاَنَّهُمْ لَا يُصِيْبُهُمْ ظَمَاٌ وَّلَا نَصَبٌ وَّلَا مَخْمَصَةٌ فِيْ سَبِيْلِ اللّٰهِ وَلَا يَطَـُٔوْنَ مَوْطِئًا يَّغِيْظُ الْكُفَّارَ وَلَا يَنَالُوْنَ مِنْ عَدُوٍّ نَّيْلًا اِلَّا كُتِبَ لَهُمْ بِهٖ عَمَلٌ صَالِحٌۗ اِنَّ اللّٰهَ لَا يُضِيْعُ اَجْرَ الْمُحْسِنِيْنَ ( التوبة: ١٢٠ )
Maa kaana li ahlil Madeenati wa man hawlahum minal A'raabi ai yatakhallafoo 'ar-Rasoolil laahi wa laa yarghaboo bi anfusihim 'an nafsih; zaalika bi annahum laa yuseebuhum zama unw wa laa nasabunw wa laa makhmasatun fee sabeelil laahi wa laa yata'oona mawti'ai yagheezul kuffaara wa laa yanaaloona min 'aduwwin nailan illaa kutiba lahum bihee 'amalun saalih; innal laaha laa yudee'u ajral muhsineen (at-Tawbah 9:120)
It was not [proper] for the people of Madinah and those surrounding them of the bedouins that they remain behind after [the departure of] the Messenger of Allah or that they prefer themselves over his self. That is because they are not afflicted by thirst or fatigue or hunger in the cause of Allah, nor do they tread on any ground that enrages the disbelievers, nor do they inflict upon an enemy any infliction but that it is registered for them as a righteous deed. Indeed, Allah does not allow to be lost the reward of the doers of good. (At-Tawbah  : 120)
1 Mufti Taqi Usmani
It was not (permissible) for the people of Madīnah and for those around them of the Bedouins to stay behind abandoning the Messenger of Allah, nor to prefer their own lives to his life. That is because whatever thirst or fatigue or hunger strikes them in the way of Allah, and whenever they step into a place which infuriates the infidels, and whenever they make a gain from an enemy, a virtuous deed is credited to their account. Surely, Allah does not nullify the reward of the virtuous.