The reason is that you disobeyed, just as Allah the Exalted says: “Until, when you lost heart, fell to disputing about the matter, and disobeyed after He had shown you what you love” (Āl ʿImrān 3:152)—in other words, the very thing you detest befell you.
What transpired did so for momentous, far-reaching purposes that Allah set forth in Sūrah Āl ʿImrān. Al-Ḥāfiẓ Ibn al-Qayyim (d. 751 AH) expounded on them with superb insight—unsurpassed, in my view—in his book Zād al-Maʿād, where he details the profound lessons drawn from this campaign.
To resume the narrative: the Messenger (peace and blessings be upon him) took up a sword and said to his Companions, “Who will take this sword from me?” All of them replied, “We will take it,” raising and stretching out their hands, each one saying, “I will, I will.” He then asked, “Who will take it with its due right?” At that, the group hesitated, for they knew what its right entailed. They feared that its right might be so great that they could not meet it, and that, having accepted the sword on the Prophet’s covenant, they might then fail to fulfil it. But Allah enabled Abū Dujānah (may Allah be pleased with him), who said, “I will take it with its right.” He accepted it on that condition—namely, that he would strike with it until it broke—and he fought with it, splitting the skulls of the idolaters.
This shows that a person should seize the opportunity to do good without delay, seeking Allah’s help; for when someone relies on Allah and thinks well of Him, Allah will aid him.
Many people consider acts of worship too burdensome and therefore retreat. The proper counsel to such a person is: seek Allah’s help, place your trust in Him; and if you do so and embark on what pleases Him—then rejoice