And Allāh had certainly fulfilled His promise to you when you were killing them [i.e., the enemy] by His permission until [the time] when you lost courage and fell to disputing about the order [given by the Prophet (ﷺ)] and disobeyed after He had shown you that which you love. Among you are some who desire this world, and among you are some who desire the Hereafter. Then He turned you back from them [defeated] that He might test you. And He has already forgiven you, and Allāh is the possessor of bounty for the believers.
The Prohibition of Obeying the Disbelievers; the Cause of Defeat at Uhud
Allah warns His believing servants against obeying the disbelievers and hypocrites, because such obedience leads to utter destruction in this life and the Hereafter. This is why Allah said,
As obvious, the noble Companions made an error of judgement during the battle of Uhud which forms the subject of admonition and correction in the previous continuity of verses. But, equally worth noticing here are the graces of Allah Almighty showered on the noble Companions side by side with the element of warning. To begin with, by saying لِيَبْتَلِيَكُمْ (so that He may test you) it was made clear that this temporary setback did not come as punishment, rather, it was to test them. Then, comes the statement, وَلَقَدْ عَفَا عَنكُمْ which very clearly proclaims: And, of course, We have forgiven you.'
Did the Noble Companions tilt towards the material?
As stated in the verses, the noble Companions were split in two groups at that time; some sought the mundane while others sought the Hereafter. The question is as to what was done by these revered Companions which identifies them with the seekers of the mundane. Obviously, it was their intention to go and collect spoils which has been equated with the seeking of the mundane. Let us now figure out the reality. If they had held on to their assigned post of duty and, as a result, had not taken part in the collection of spoils, would it have made their due share in the spoil any lesser? And, did their participation entitle them to some larger share? The Law of Spoils as authentically proved by the Qur'an and Hadith is common knowledge. They, as the first observers of the operation of the Law, knew it beyond doubt that their due share in the spoils was under no condition subject to being more or less. The fact was that their share in the spoils would have remained the same whether they helped in the collection of spoils or remained on guard at the appointed place of duty.
Keeping this in view, it is obvious that their action cannot be classed as the unqualified pursuit of the material. Instead of that, it is participation in what مجاہدین mujahidin are supposed to do. However, given the workings of human nature, the thought of spoils entering their hearts at that time is not totally unimaginable. But, Allah Almighty has His ways with people; He very much likes to see the hearts of the Companions of His Messenger clean and untouched even by the remotest idea of any tilt towards material possession. So, this very idea of going to possess things of دنیا dunya has been equated with 'seeking of the mundane' which explains the element of divine distaste for the action.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 151–152
The temporary defeat of the Muslims at the battle of Uhud gave an opportunity to the opponents of Islam to prove their stand that the credo of the Prophet and his companions was not a divine matter. It was just the boyish enthusiasm of certain people and now they were suffering for it. Their enemies would point out that had it pertained to God, they would never have been defeated at the hands of their opponents. However, such happenings, even if the results of the Muslims’ own errors, are, at all events, ‘test papers’ from God. A happening like that of Uhud must take place in this world in order to find out who are the ones who truly trust in God and who are the ones who are to fall by the wayside. Such happenings serve as a two-sided trial for the believer. He passes the test only if he perseveres at all times, is not influenced by the adverse remarks of others and is not discouraged by temporary setbacks.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.