All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
Abu Hurayrah narrated that the Prophet, sallallaahu ʻalayhi wa sallam, said:
“One of the earlier Prophets who was out on a military expedition proclaimed among his people that no man who had married a woman with whom he wished to consummate the marriage but had not yet done so, who had built houses on which he had not yet erected the roofs, or who had bought sheep or pregnant she-camels and was expecting them to produce young, should follow him. He then went on the expedition and approached the town at the time of the ʻAsr prayer or a little before it. He then said to the Sun, 'You are receiving orders and I am receiving orders from Allaah. O Allaah stop the sun!' It was held back till Allaah granted him victory...” [Al-Bukhari and Muslim]
As for the reason for this incident, the battle took place in the late afternoon hours of a Friday; that Prophet of Allaah feared that if they could not attain victory and conquer the town before sunset, Saturday would come, and fighting was prohibited on Saturdays; their enemies would then have the opportunity to shield their town and take further preparations. Therefore, he implored Allaah, The All-Merciful and All-Generous Lord, and He answered his supplication.
Al-Mullaa ʻAli Al-Qaari commented on this hadeeth saying:
“The hadeeth reads, 'He (that Prophet) said to the Sun, 'You are receiving orders and I am receiving orders,'' meaning that he was following the commands of Allaah, fighting against those people, and conquering this village just as the Sun receives the command of Allaah to set. He fought against the giants on a Friday, and when the Sun was about to set, he feared that he would not attain victory before sunset and then Saturday on which it was forbidden to fight, would come. Therefore, he supplicated Allaah, 'O Allaah, stop the sun!' Allaah answered his supplication and it was stopped for him until Allaah granted him victory.” [Mirqaat Al-Mafaateeh Sharh Mishkaat Al-Masaabeeh: 6/2602]
Allaah knows best.