Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:3:152

And Allah had certainly fulfilled His promise to you when you were killing 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 Allah is the possessor of bounty for the believers.  

God has been true to His promise, towards you, of giving you victory, when you slew them by His leave, by His will, until you lost heart, ˹until˺ you shrank from battle, and quarrelled, disagreed, over the command, that is, the command of the Prophet (s) that you remain at the foot of the mountain for the arrow attack, some of you saying, ‘Let us depart, for our comrades have been given victory’, others saying, ‘We should not disobey the command of the Prophet (s)’; and you disobeyed, his command, and abandoned your station in search of the booty, after He, God, had shown you what you longed for, of assistance (the response to the ˹clause containing˺ idhā is indicated by what precedes it, that is to say, ‘˹when you lost heart˺ He denied you His assistance’). Some of you desired this world, abandoning his station for the sake of the booty; and some of you desired the Hereafter, holding to it until he was slain, such as ‘Abd Allāh b. Jubayr and his companions. Then He turned you away (thumma sarafakum is a supplement to the response of the ˹clause containing˺ idhā, implied to be raddakum bi’l-hazīma ˹‘He turned you back in defeat’˺) from them, the disbelievers, so that He might try you, that He might test you and so make manifest the sincere ones from those otherwise; yet now He has pardoned you, what you have done, and God is Bounteous to the believers, with pardon.
القرآن:٣:١٥٢

وَلَقَدْ صَدَقَكُمُ اللَّهُ وَعْدَهُ إِذْ تَحُسُّونَهُمْ بِإِذْنِهِ ۖ حَتَّىٰ إِذَا فَشِلْتُمْ وَتَنَازَعْتُمْ فِي الْأَمْرِ وَعَصَيْتُمْ مِنْ بَعْدِ مَا أَرَاكُمْ مَا تُحِبُّونَ ۚ مِنْكُمْ مَنْ يُرِيدُ الدُّنْيَا وَمِنْكُمْ مَنْ يُرِيدُ الْآخِرَةَ ۚ ثُمَّ صَرَفَكُمْ عَنْهُمْ لِيَبْتَلِيَكُمْ ۖ وَلَقَدْ عَفَا عَنْكُمْ ۗ وَاللَّهُ ذُو فَضْلٍ عَلَى الْمُؤْمِنِينَ  

{ولقد صدقكم الله وعده} إياكم بالنصر {إذ تحسونهم} تقتلونهم {بإذنه} بإرادته {حتى إذا فَشِلْتُمْ} جبنتم عن القتال {وتنازعتم} اختلفتم {في الأمر} أي أمر النبي ﷺ بالمقام في سفح الجبل للرمي فقال بعضكم: نذهب فقد نُصر أصحابنا وبعضكم: لا نخالف أمر النبي ﷺ {وعصَيتم} أمره فتركتم المركز لطلب الغنيمة {من بعد ما أراكم} اللهُ {ما تحبون} من النصر وجواب إذا دل عليه ما قبله أي منعكم نصره {منكم من يريد الدنيا} فترك المركز للغنيمة {ومنكم من يريد الآخرة} فثبت به حتى قتل كعبد الله بن جبير و أصحابه {ثم صرفكم} عطف على جواب إذا المقدر ردَّكم للهزيمة {عنهم} أي الكفار {ليبتليكم} ليمنحنكم فيظهر المخلص من غيره {ولقد عفا عنكم} ما ارتكبتموه {والله ذو فضل على المؤمنين} بالعفو.