Praise be to Allah.
There are differences among the scholars concerning this matter. The correct opinion is that Tahiyyat al-masjid is permitted at all times, even after Fajr and after ‘Asr, because of the general applicability of the hadith “When any one of you enters the Mosque, he should not sit down until he has prayed two rak`ahs.” (Sahih – agreed upon)
Tahiyyat al-masjid is one of the prayers that is done for a specific reason, like Salat al-Tawaf (prayer done after circumambulating the Ka`bah) and Salat al-Kusuf (prayer at the time of an eclipse). The correct view concerning all of these is that it is permissible to do these at times when prayer is generally disallowed, like making up missed prayers.
Concerning Salat al-Tawaf, the Prophet (peace and blessings of Allah be upon him) said: “O Banu ‘Abd Manaf, do not prevent anyone from circumambulating this House and praying at any time of night or day.” (Reported by Imam Ahmad and the authors of Sunan with a sahih isnad)
Concerning Salat al-Kusuf , he (peace and blessings of Allah be upon him) said: “The sun and moon are two of the Signs of Allah; they are not eclipsed because of the death or life of anyone.” (1/332)
And Allah knows best.