Surah Aal-i-Imraan

3:166

وَمَآ أَصَٰبَكُمْ يَوْمَ ٱلْتَقَى ٱلْجَمْعَانِ فَبِإِذْنِ ٱللَّهِ وَلِيَعْلَمَ ٱلْمُؤْمِنِينَ

And what struck you on the day the two armies met was by permission of Allah that He might make evident the [true] believers.

Tafsir 3:166

The death, wounds and defeat you suffered on the day of Uḥud, when your army and the army of the idolaters met, was by the permission and decree of Allah, with far-reaching wisdom behind it: to make it clear who truly had faith.