Allah Most High says in Surah Kahf:
And you see that the sun, when it rises, moves to the right from their cave and inclines obliquely from them to the left when it sets while they are (lying) in the open chamber of the cave. This (change of the sun’s course) is one of the (great) Signs of Allah’s (Might). He whom Allah guides is the one who is rightly guided, but one whom He holds strayed you will not find for him any Wali (friend to help) and Murshid (guide to show the path). Surah Kahf (18:17)
This is a reality that the sun moves in its own orbit. It neither delays nor makes haste anywhere in its path. It does not swerve a hairbreadth’s worth of distance from its path. This is the system of nature. In spite of all this, Allah Most High granted the People of the Cave such excellence that for the whole time they spent in the cave, the sun swerved from its path. When it would rise on the earth, it would move to its right and while setting, it would move to the left, so that the rays of the sun don’t fall on them.
This is a sign of the power of Allah Most High and a miracle of the People of the Cave.
Imam Razi writes in the Tafseer of this verse:
Translation: The rising and setting of the sun in this way is against what usually happens and is a great miracle, which Allah Most High has granted to the People of the cave. (Tafseer Kabeer, Surah Kahf, 17)