As Salamu Alaikum wa Rahmatullahi wa Barakatuhu
Question
There is much talk about Tahiyyatul-Masjid: Some say that it should not be done during the times when it is reported that prayer is forbidden, such as at the times of sunrise and sunset. Others say that it is permissible since the reasons for it are not restricted by any time and that it should be done even if half the sun had set. I request a detailed explanation of this.
Answer
There is some disagreement amongst the scholars in this matter, but the correct view is that Tahiyyatul-Masjid is lawful at all times, even after Fajr and after Asr based upon the general meaning of the words of the Prophet (Sallallahu Alayhi wa Sallam)
If any of you enters the mosque, he should not sit until he has prayed two Rakahs. (Al-Bukhari no 1163 and Muslim (714)
Also, it is a prayer that there is a reason to perform, like Salat At-Tawaf [*] and Salat Al-Khusuf, [**] and the correct view in all of these is that they should be performed at all of the times when prayer is (normally) prohibited, just like making up for an obligatory prayer which one has missed, based upon the words of the Prophet (Sallallahu Alayhi wa Sallam) regarding Salat At-Tawaf:
O people of (the tribe of) Abdi Manaf! Do not prevent anyone from performing Tawaf of this House and praying anytime of the night or day that he wishes. (Abu Dawud 1894, At-Tirmidhi 868 and Ahmad 4:81)
And he (Sallallahu Alayhi wa Sallam) said, regarding Salat Al-Kusuf:
Verily the sun and the moon are two Signs among the Signs of Allaah, they are not eclipsed for the death or the birth of any man, so if you see them, pray and supplicate, until what you are suffering is removed. (Al-Bukhari 1040 and Muslim 901)
And he (Sallallahu Alayhi wa Sallam) said:
Whoever slept through a prayer or forgot it, must make up for it as soon as he remembers it, and there is no expiation for it except this. (Al-Bukhari 597 and Muslim 684)
All of these Hadiths extend to include the times when prayer is prohibited and other times. This saying is the preferred view of Shaikh Al-Islam, Ibn Taymiyyah and his student, the great scholar, Ibn Al-Qayyim - may Allaahs mercy be on both of them. And Allaah is the Granter of success.
Shaikh Ibn Baz (Rahimahullah)
Reference: Fatawa Islamiyah Volume 2 Page 286-287
[*] Salat At-Tawaf: A two rakah prayer following circumambulation of the Kabah during Hajj and Umrah.
[**] Salat Al-Khusuf: Prayer of the lunar or solar eclipse.