Abu Hurairah (May Allah be pleased with him) reported that the Messenger of Allah (ﷺ) said:
"One of the earlier Prophets who was out on an expedition proclaimed among his people that no man should follow him who had married a woman with whom he wished to cohabit but had not yet done so, or who had built houses on which he had not yet put the roofs, or who had bought sheep or pregnant she-camels and was expecting them to produce young. He, then, went on the expedition and approached the town at the time of the 'Asr prayer or little before it. He then told the sun that both it and he were under command and prayed Allah to hold it back for them, so it was held back till Allah gave him victory. He collected the spoils and it (meaning fire) came to devour these, but did not. He said that among the people there was a man who stole from the booty. He told them that a man from every tribe must swear allegiance to him, and when a man's hand stuck to his, he said: "There is thief among you and every individual of your tribe must swear allegiance to me". (In course of swearing of allegiance,) hands of two or three persons stuck to his hand. He said: "The thief is among you". They brought him a head of gold like a cow's head and when he laid it down, the fire came and devoured the spoils. Spoils were not allowed to anyone before us, then Allah allowed spoils to us as He saw our weakness and incapacity and allowed them to us".[Al-Bukhari and Muslim].
Arabic/English book reference: Book 1, Hadith 58