Is it permissible to pray salutation to the mosque (Tahiyyatul-Masjid) during (Makrooh) undesirable times? The Hadith says: Narrated Abu Qatada Al-Aslami: Allah's Apostle said, "If anyone of you enters a mosque, he should pray two Raka'h before sitting." Another Hadith says: Narrated Abu Huraira: The Prophet had forbidden: the offering of two prayers, one after the morning compulsory prayer till the sun rises, and the others, after the 'Asr prayer till the sun sets. Narrated Humran bin Abbas: Muawiya said (to the people), "You offer a prayer which we, who were the companions of the Prophet never saw the Prophet offering, and he forbade its offering," i.e. the two Raka'h after the compulsory 'Asr prayer. What is the rulings to offer Salat during these times?
Praise be to Allah, the Lord of the Worlds; and blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
If you enter a mosque just before sunset it is better to wait till the sun disappears in sunset and then perform two Rakah's. By this practice one may avoid the differences of scholars' opinions and at the same time practise all that is mentioned in the Ahadith, i.e., the Ahadith which prohibit performing voluntary prayers after 'Asr prayer and those which enjoin performing two Rakah's whenever one enters a mosque.
As for performing Tahiyyah-tul-Masjid (the prayer of salutation to the mosque) after the entering of the time of Fajar prayer, many scholars do not like performing any prayer after the entering of the time of Fajar prayer. The basis of this opinion is the Hadith narrated from Ibn Umar he said that the Prophet said: "Who is present here must convey the message to the one who is absent that no one should perform any prayer after Fajar except two prostrations (two Raka'h)". (This Hadith is good and reported by Abu Dawood).
Meanwhile Shafites, Hanbalites and a group of authentic research scholars, such as Ibn Taymiyah, Ibn al-Qayyim, al-Shaukani and others, reasoned that prayers at such times are allowed if the person has a reason for that prayer, like Tahiyyat-tul-Masjid, the prayer one performs after making ablution, and so on.
Their evidence for that is the fact that the Ahadith which prohibit praying in such times are common while the Ahadith enjoining performing certain voluntary prayers are specific, thus there is no contradiction between those two types of Ahadith. So, Insha Allah, the latter opinion is more preponderant than others.
Allah knows best.
You can search for fatwa through many choices