Al Imaam Ibnil Qayyim Mentions when discussing the benefits related to what occurred at the battle of Uhud of defeat:
From its benefits: Is that Allah tests the servitude of His true allies and His party (among mankind), by testing them with good times and with calamities, and by testing them with what they love and what they dislike. And (by testing them) with victories, and likewise with the victories of their enemies over them. If they remain steadfast upon obedience and worship during that which they love and that which they dislike, then they are His worshippers truly. They are not like those who worship Allah on the verge of one state (alone), namely good times and the presence of blessings and well-being.
From its benefits: Is that if He – May he be glorified – were to aid them constantly, and were to grant them victory over their enemies in every instance, and established them and made them overpower their opponents on every occasion, then it would have bred transgression within them, and they would have become proud and they would have put on airs. Thus, if they were constantly granted aid and victory, they would have been in a state similar to the state they would have been in had they been constantly granted abundant sustenance. Thus, the servant is not rectified except through good times and hardships, difficulties and prosperity, (Allah) giving to them and Him withholding. He is the one that arranges the affairs of his servant as his wisdom dictates, and He is well-Acquainted with them, All Seeing.
From its benefits: Is that when He tests them with being overpowered, having their spirits broken, and suffering defeat, they humble themselves, feel dejection and experience subdual, this necessitates from Him that He (will go on) to ennoble and aid them, for certainly the honourable robe of the aid (of Allah) comes about when one adorns himself with humility to Him, being broken in front of Him, and realising ones need for him.
Allah – The Most High says: “Indeed Allah did aid you at (the battle of) Badr though you were weak” (Aali Imraan Vs 123)
And Allah – The Most High said: “And on the Day of Hunain when you rejoiced at your great numbers but it availed you naught…” (Taubah Vs 25)
Thus when Allah wished to ennoble, rectify, mend and aid His servant, He first breaks him, then His rectification of him, and His granting him aid, is in accordance to his humility and lowliness (before his lord)..”
(Zaadul Ma’aad 3/198)
@abuhakeembilal