The Prophet ﷺ said one day, "Do you know where this sun goes?"They replied, "Allah and His Messenger know best."He said, "It travels until it reaches its resting place beneath the Throne, where it falls down in prostration. It remains like that until it is told, 'Rise, return to where you came from,' so it returns and rises in the morning from its place of rising. Then it travels until it reaches its resting place beneath the Throne, where it falls down in prostration. It remains like that until it is told, 'Rise, return to where you came from,' so it returns and rises in the morning from its place of rising. Then it travels, and the people notice nothing unusual about it, until it reaches that resting place of its beneath the Throne, and it is told, 'Rise, rise in the morning from your place of setting in the west.' So it rises in the morning from its place of setting in the west."Then the Messenger of Allah ﷺ said, "Do you know when that will be? That will be when, 'No soul will benefit from its faith if it had not believed before or earned good through its faith.' [Anam 6:158]"
أن النبي ﷺ قال يوما: أتدرون أين تذهب هذه الشمس؟ قالوا: الله ورسوله أعلم. قال: إن هذه تجري حتى تنتهي إلى مستقرها تحت العرش، فتخر ساجدة، فلا تزال كذلك حتى يقال لها: ارتفعي، ارجعي من حيث جئت، فترجع، فتصبح طالعة من مطلعها، ثم تجري حتى تنتهي إلى مستقرها تحت العرش، فتخرساجدة، ولا تزال كذلك حتى يقال لها: ارتفعي، ارجعي من حيث جئت، فترجع، فتصبح طالعة من مطلعها، ثم تجري لا يستنكر الناس منها شيئا حتى تنتهي إلى مستقرها ذاك تحت العرش، فيقال لها: ارتفعي، أصبحي طالعة من مغربك، فتصبح طالعة من مغربها، فقال رسول الله ﷺ: أتدرون متى ذاكم؟ ذاك حين: {لا ينفع نفسا إيمنها لم تكن ءامنت من قبل أو كسبت في إيمنها خيرا}[سورة الأنعام: ١٥٨].
Bukhari related it in the tafsir (4802), and Muslim in the Book of Faith (159), both through the route of Ibrahim bin Yazid Taymi, from his father, from Abu Dharr, who said, then he mentioned it. The wording given is Muslim's, while Bukhari's wording is abridged.