Solāh Tahiyyatul Masjid is Permitted At All Times When Solāh is Not Allowed
If a person enters the Masjid during one of the time when making prayer is makrūh (eg. sunrise, sunset, zawāl...), does he still have to pray two rak’ahs of Tahiyyatl-Masjid.
In the Name of Allah, the Most Gracious, the Most Merciful,
All praise and thanks is due to Allah, and peace and blessings be upon His Messenger.
Tahiyyatul-Masjid is permitted at all times
There are differences of view among the scholars concerning this matter; the correct opinion is that Solāh Tahiyyatul-Masjid is permitted at all times (when prayer is generally disallowed), even after Fajar and after ‘Asar, because of the general applicability of the hadith:
Abu Qatadah (radiyallahu`anhu) reported that the Prophet (Sallallāhu `alayhi wasallam) said:
"Whoever enters a mosque should perform two Rak`at (SolāhTahiyyatul-Masjid) before sitting"
This is one of the prayers that are done for a specific reason, like Solāh al-Tawāf (prayer done after circumambulating the Ka’abah) and Solāt al-Kusūf (Solāh at the time of an eclipse). It is permissible to be performed at times when prayer is generally disallowed, like making up missed Solāh.
In relation to Solāh al-Tawāf, the Prophet (Sallallāhu `alayhi wasallam) said:
“O Banu ‘Abd Manāf, do not prevent anyone from circumambulating this House and praying at any time of night or day.”
[Reported by Imām Ahmad and the authors of Sunan with a sahīh isnād]
And in relation to Solāh al-Kusūf, the Prophet (Sallallāhu `alayhi wasallam) said:
“The sun and moon are two of the Signs of Allāh; they are not eclipsed because of the death or life of anyone.”
[Islam Q&A (Fatāwa No: 306)]
Entering the mosque and the adzān was being given for the prayer
When you enter the mosque and the adzān was being given for the prayer it is better to respond to the adzān first, then you may pray Tahiyyatul-Masjid, so as to combine two virtuous deeds. But the issue is flexible.
[Al-Lajnah al-Dā’imah Li’l-Buhūth al-‘Ilmiyyah wa’l-Iftaa’, 7/273]
Entering the mosque and the imam may order that the Iqāmah
But in the case the imam may order that the Iqāmah be given for Fajar prayer, after which there is no need for Tahiyyatul-Masjid, because praying the fardu (obligatory) prayer is sufficient and means that there is no longer any need to do Tahiyyatul-Masjid. The member of the congregation may also forego Tahiyyatul-Masjid if he enters the mosque when the Iqāmah is being given.
[Al-Lajnah al-Dā’imah Li’l-Buhūth al-‘Ilmiyyah wa’l-Iftaa’, 7/272]
Allah Almighty knows best.
[Adapted from Islam Q&A (Fatāwa No: 306; No 5070; No: 5074)]