What does the Qur'an say about the prostration of the sun:
If you search in the Qur'an you will find a lots of Verses who tell us that the sun does prostrate and some who tell/indicate us "how":
- In Surat al-Hajj (22:18) the prostration of the sun is clearly mentioned!
- In other suwar (surahs) it's mentioned that all creations do prostrate like in Surat an-Nahl(16:49) and Surat al-Hashr (59:24).
- In other places we find that they do prostrate but in their own way like in Suart al-Isra' (17:44) and Surat an-Nur (24:41).
so we have to believe that the sun does prostrate but we don't know how, and asking how would be considered (by most scholars) as inappropriate!
Is this Hadith a contradiction to science?
The Verse mentioned above are the reason why all scholars who read the Hadith you mentioned accepted it, even if they knew that day and night are the result of earth's rotation around it's axis. And here's a fatwa showing that this hadith is no contradiction to science! (By the Way there are many Versions of this hadith in Sahih al-Bukhari and other Hadith collections, some of them have been regarded as less reliable then others)
Ibn Taymiyah (may Allah have mercy on him) said:
The heavenly bodies are round, according to the Muslim scholars among
the Sahaabah and those who followed them in guidance; that was also
proven from them with isnaads mentioned in the appropriate places. In
fact, more than one of the Muslim scholars narrated that there was
consensus among the Muslims on that point.
About the Hadith and it's meaning
- First be aware that the Hadith doesn't say that the sun is prostrating at sunset but underneath the Throne. So this normally should end the misunderstanding of the day and night matter!
- Scholars have many opinion on this prostration, some say the sun is prostrating all along in each position that it takes during her rotation. Some say it prostrates once a year... there are also some more or less scientific explanations!
- Scholars have different opinion on the appointed term:
- Some say that this ends or will be at the end of dunya.
- About the Verse (36:38) some scholars quote some Qira-a Shadhah of ibn 'Abas and ibn Masu'd (May Allah be pleased with them) which says it has no appointed term (in dunya)
"والشمس تجري لا مستقر لها"
which differs from the Mushaf
" والشمس تجري لمستقر لها"
Read for example in tafsir al-Qurtubi.
- The Version of this Hadith in Sahih Muslim is somehow confirming the last statement. As once the permission to go on her course wouldn't be given this would be (lead to) the end of dunya and as mentioned their the appointed term.
Conclusion:
From this Hadith we can conclude only that the sun is worshiping/prostrating while rotating. And this has no effect or better relation on day and night or on her rotation!
See also in Arabic
And Allah knows best