The Messenger of Allah ﷺ mentioned several hadith, among them this one. The Messenger of Allah ﷺ said, "A prophet from among the prophets went out on a military campaign, and he said to his people, 'No man shall follow me who has married a woman and wishes to consummate the marriage but has not yet done so, nor anyone who has built a house but has not yet raised its roof, nor anyone who has bought sheep or pregnant she-camels and is waiting for them to give birth.'So he set out on the campaign, and he drew near the town around the time of the afternoon prayer or close to it. He said to the sun, 'You are under command and I am under command. Allah, hold it back for me a while.' So it was held back for him until Allah granted him victory.They gathered the spoils, and a fire came forth to consume them, but it refused to take them. He said, 'Among you there is one who has stolen from the spoils. So let one man from every tribe give me his pledge.' They gave him their pledges, and the hand of one man stuck to his hand. He said, 'The theft is in your tribe. Let your tribe pledge to me.' They pledged to him, and the hands of two or three men stuck to his. He said, 'The theft is among you. You have stolen.'So they brought out for him something like a cow's head made of gold. They placed it with the rest of the spoils on the open ground, and the fire came and consumed them.Spoils of war were not made lawful for anyone before us. That is because Allah saw our weakness and inability, so He made them lawful for us."
عن رسول الله ﷺ، فذكر أحاديث منها: وقال رسول الله ﷺ: غزا نبي من الأنبياء، فقال لقومه: لا يتبعني رجل قد ملك بضع امرأة، وهو يريد أن يبني بها ولما يبن، ولا آخر قد بني بنيانا ولما يرفع سقفها، ولا آخر قد اشترى غنما أو خلفات وهو منتظر ولادها. قال: فغزا، فأدنى للقرية حين صلاة العصر أو قريبا من ذلك، فقال للشمس: أنت مأمورة وأنا مأمور، اللهم احبسها علي شيئا. فحبست عليه حتى فتح الله عليه قال: فجمعوا ما غنموا، فأقبلت النار لتأكله، فأبت أن تطعمه، فقال: فيكم غلول، فليبايعني من كل قبيلة رجل. فبايعوه، فلصقت يد رجل بيده، فقال: فيكم الغلول، فلتبايعني قبيلتك. فبايعته، قال: فلصقت بيد رجلين أو ثلاثة، فقال: فيكم الغلول، أنتم غللتم. قال: فأخرجوا له مثل رأس بقرة من ذهب. قال: فوضعوه في المال وهو بالصعيد، فأقبلت النار فأكلته. فلم تحل الغنائم لأحد من قبلنا، ذلك بأن الله تبارك وتعالى رأى ضعفنا وعجزنا، فطيبها لنا.
Bukhari narrated it in the chapter on the obligation of khumus (3124), and Muslim in jihad and expeditions (1747), both of them from Abu Kurayb Muhammad bin Ala, who said, Ibn Mubarak narrated to us, from Mamar, from Hammam bin Munabbih, who said, this is what Abu Hurairah narrated to us, and he mentioned it. The wording given here is that of Muslim.