The Prophet ﷺ said to Abu Dharr when the sun had set, "Do you know where it goes?"I said, "Allah and His Messenger know best."He said, "It travels until it prostrates beneath the Throne, then it asks permission and is granted permission. A time is near when it will prostrate but its prostration will not be accepted, and it will ask permission but permission will not be granted to it. It will be told, 'Return from where you came,' so it will rise from its place of setting. That is the meaning of His statement, "And the sun runs toward its resting place. That is the decree of the Almighty, the All-Knowing" [Ya-Sin 36:38]."
قال النبي ﷺ لأبي ذر حين غربت الشمس: أتدري أين تذهب؟ قلت: الله ورسوله أعلم. قال: فإنها تذهب حتى تسجد تحت العرش، فتستأذن، فيؤذن لها، ويوشك أن تسجد، فلا يقبل منها، وتستأذن فلا يؤذن لها، يقال لها: ارجعي من حيث جئت، فتطلع من مغربها. فذلك قوله تعالى: {والشمس تجرى لمستقر لها ذلك تقدير العزيز العليم}.
Bukhari narrated it in the Book of the Beginning of Creation (3199), and Muslim in the Book of Faith (159), both through Amash, from Ibrahim Taymi, from his father, from Abu Dharr, who said, then he related it. The wording given here is Bukhari's, and Muslim's wording is similar.