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.
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 (sallallaahu alaihi wa sallam): If any of you enters the mosque, he should not sit until he has prayed two Rakahs.  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 (sallallaahu alaihi 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.  And he (sallallaahu alaihi 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.  And he (sallallaahu alaihi 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,.  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.
 Al-Bukhari no. 1163 and Muslim no. 714  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.  Abu Dawud no. 1894, At-Tirmithi no. 868 and Ahmad 4:81  Al-Bukhari no. 1040 and Muslim no. 901  Al-Bukhari no. 597 and Muslim no. 684
Shaykh `Abdul-`Azeez Bin Baz
Fatawa Islamiyah Vol. 2 Page 286