Abu Hurairah reported,

The Messenger of Allah ﷺ said, "One of the prophets went out on a military campaign. He said to his people, 'Let no man follow me who has married a woman and wishes to consummate the marriage but has not yet done so, nor anyone who has built houses but has not yet raised their roofs, nor anyone who has bought sheep or pregnant camels and is awaiting their offspring.'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. O Allah, hold it back for us.' So it was held back until Allah granted him victory.He then gathered the spoils, and the fire came to consume them, but it would not devour them. He said, 'There is one among you who has stolen from the spoils. Let one man from each tribe pledge allegiance to me.' The hand of one man stuck fast to his hand, and he said, 'The theft is in your tribe. Let your tribe pledge allegiance to me.' Then the hands of two or three men stuck to his hand, and he said, 'The theft is among you.'So they brought a head of gold like the head of a cow and placed it down. The fire then came and consumed the spoils. Then Allah permitted the spoils of war to us, for He saw our weakness and inability, so He made them lawful for us."

Bukhari 3124

Sahih

حدثنا محمد بن العلاء حدثنا ابن المبارك عن معمر عن همام بن منبه

عن أبي هريرة رضي الله عنه قال

قال رسول الله ﷺ غزا نبي من الأنبياء فقال لقومه لا يتبعني رجل ملك بضع امرأة وهو يريد أن يبني بها ولما يبن بها ولا أحد بنى بيوتا ولم يرفع سقوفها ولا أحد اشترى غنما أو خلفات وهو ينتظر ولادها فغزا فدنا من القرية صلاة العصر أو قريبا من ذلك فقال للشمس إنك مأمورة وأنا مأمور اللهم احبسها علينا فحبست حتى فتح الله عليه فجمع الغنائم فجاءت يعني النار لتأكلها فلم تطعمها فقال إن فيكم غلولا فليبايعني من كل قبيلة رجل فلزقت يد رجل بيده فقال فيكم الغلول فليبايعني قبيلتك فلزقت يد رجلين أو ثلاثة بيده فقال فيكم الغلول فجاءوا برأس مثل رأس بقرة من الذهب فوضعوها فجاءت النار فأكلتها ثم أحل الله لنا الغنائم رأى ضعفنا وعجزنا فأحلها لنا

البخاري 3124صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Obligation of the fifth
Chapter
Saying of the Prophet ﷺ, "Spoils of war have been made lawful for you"
Numbering
Darussalam 3124
Bukhari 3124