The Prayer of Greeting the Mosque (tahiyyat al-masjid)
In the name of Allah, the inspirer of truth,
The prayer of greeting the mosque is a confirmed sunna once a day, and recommended thereafter.
It is best to perform it before sitting, though it remains called for even after one does.
If one enters the mosque and there is not enough time to perform it before the obligatory prayer commences, or if one needs to perform the confirmed sunna of Zuhr, or if the congregational prayer has started, then one can simply intend it along with the prayer one is going to perform.
Ibn Qudama al-Maqdisi, the Hanbali imam, stated in his Mughni: [1.1048]
“It is a sunna for the one who enters a mosque not to sit until they pray two rakats before sitting, because Abu Qatada (Allah be pleased with him) narrated that the Messenger of Allah (Allah bless him & give him peace) said, “If one of you enters the mosque, do not sit until you pray two rakats.” [Bukhari and Muslim]
If one sits before praying, it is a sunna to stand up and pray… ”
Imam al-Haskafi said in his Durr al-Mukhtar, which is the most important commentary in the Hanafi school for the details of legal rulings,
“(It is a sunna to greet) the Lord of (the mosque by praying two rakats. Performing the obligatory prayer) or other than it … (can take its place) even without having intended it.
It is sufficient [f: in order to fulfill the sunna] to perform it once for the whole day.
This sunna is not lifted in our school if one sits down before praying it – Bahr.
I say: In al-Diya’, quoting al-Qut: Whoever is unable to perform it, because of speech or the like, it is recommended for them to say the four tasbihs [f: Subhan Allah, Alhamdulillah, La Ilaha Illa Allah, Allahu Akbar] four times.”
Imam Ibn Abidin commented on this in his Radd al-Muhtar, which is the most reliable reference for the fatwa positions in the Hanafi school,
“It is mentioned in al-Halba [of Ibn Amir Hajj al-Halabi]: Scholarly consensus (ijma`) has been mentioned about the prayer of greeting the mosque being a sunna.
However, our scholars hold that it is disliked (makruh, f: prohibitively) in the disliked times [f: such as after the fard of Fajr until the sun has risen, when the sun is at is zenith just before zuhr time comes in, after the fard of Asr until the fard of Maghrib, and when the imam is on the minbar for the Friday sermon], giving precedence to the general interdiction over the general permission
… Al-Quhustani mentioned that it may be performed as two or four rakats, with the latter being superior.
However, if one enters after [the fard] of Fajr or Asr [f: or if one already performed the sunna of Fajr at home], then one limits oneself to exalting Allah (tasbih), declaring his Oneness (tahlil, f: by repeating ‘La Ilaha Illa Allah’), and sending blessings on the Prophet (Allah bless him and give him peace)…
This sunna is not lifted in our school if one sits down. As for the hadith reported by Bukhari and Muslim that the Messenger of Allah (Allah bless him & give him peace) said, “If one of you enters the mosque, do not sit until you pray two rakats,” it indicates that which is best to do, because of what Ibn Hibban reported in his Sahih that the Messenger of Allah (Allah bless him and give him peace) said, “O Abu Dharr! The mosque has a greeting. Its greeting is two rakats. Get up and pray them…
The exception to this sunna is the Haram of Mecca, whose greeting is tawaf (circumambulation)… ” [Ibn `Abidin, Radd al-Muhtar]
And Allah alone gives success
Answered By: Shaykh Faraz Rabbani