Indeed, those of you who turned back on the day the two armies met [at Uḥud] - it was Satan who caused them to slip because of some [blame] they had earned. But Allāh has already forgiven them. Indeed, Allāh is Forgiving and Forbearing.
Slumber Overcame the Believers; the Fear that the Hypocrites Suffered
Allah reminds His servants of His favor when He sent down on them tranquillity and slumber that overcame them while they were carrying their weapons and feeling distress and grief. In this case, slumber is a favor and carries meanings of calmness and safety. For instance, Allah said in Surat Al-Anfal about the battle of Badr,
إِذْ يُغَشِّيكُمُ النُّعَاسَ أَمَنَةً مِّنْهُ
((Remember) when He covered you with a slumber as a security from Him) 8:11.
Al-Bukhari recorded that Anas said that, Abu Talhah said, "I was among those who were overcome by slumber during the battle of Uhud. My sword fell from my hand several times and I would pick it up, then it would fall and I would pick it up again." Al-Bukhari collected this Hadith in the stories of the battles without a chain of narration, and in the book of Tafsir with a chain of narrators. At-Tirmidhi, An-Nasa'i and Al-Hakim recorded from Anas that Abu Talhah said, "On the day of Uhud, I raised my head and looked around and found that everyone's head was nodding from slumber." This is the wording of At-Tirmidhi, who said, "Hasan Sahih". An-Nasa'i also recorded this Hadith from Anas who said that Abu Talhah said, "I was among those who were overcome by slumber."
The noble Companions as evident from: وَلِيَبْتَلِيَ اللَّـهُ مَا فِي صُدُورِكُمْ (154), were actually tested through their sufferings at the battle of Uhud. This was no punishment. The objective was to make true and sincere Muslims distinct from the hypocrites. The mode was a 'test of inner qualities'.
The eloquent Qur'anic expression أَثَابَكُمْ (He awarded you sorrow), which is suggestive of punishment, can be resolved by saying that the outward form was, no doubt, that of punishment but the real purpose was a sort of affectionate correction, something similar to a well-meaning reprimand from a father to his son or a teacher to his student. In common usage, this can be called a punishment of some sort, but this is, in all reality, a form of training and correction. This is very different from a pure legal punishment.
On the occasion of Uhud, ‘Abdullah ibn Ubayy counselled that the defence of Madinah should be undertaken within the walls, instead of the Muslims boldly coming out to meet the enemy. The Prophet, however, at the instance of some other sincere Muslims, went out of the city to meet the enemy, posting his men strategically on Mount Uhud. The battle began well for the Muslims, but turned to near defeat because of the disobedience of a band of fifty archers who had been given the task of guarding a certain pass. Seeing the imminent Muslim victory, they abandoned their posts, attracted by the prospects of booty. When this victory turned into defeat, the hypocrites who had deserted the Muslims even before the battle started, on the pretext that their counsel had not been accepted by the Prophet, began to say that, had their words been heeded, this calamity could have been averted. But death is decreed by God and comes regardless of circumstances. No precautionary measure can save one from death. Such happenings, whatever their apparent reason, are wrought by God, in order that His true believers may turn to Him in repentance and become worthy of further blessings from Him. Such happenings also serve to reveal the truth about those who are not the true servants of God. When the fifty archers posted at the Mount Uhud pass saw that the Muslims had won the battle, a large number of them insisted on going in pursuit of booty. Although ‘Abdullah ibn Jubayr and a few other companions pointed out that it was against the orders of the Prophet, they deserted their posts, leaving behind eleven men. Satan thus made inroads by using the dissension already evident among them. However, when they admitted their error, they were forgiven by God, and after the initial setback, God’s succour came to them too. The Almighty struck terror into the hearts of their enemies, which resulted in their retreat, although they were just a few miles from Madinah. Had God’s succour not come, there was nothing to stop them from forcing their entry into Madinah and uprooting the nascent tree of Islam.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.