All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
It is permissible for the Muslim who enters the Masjid and sits down to stand up and perform Tahiyyat-ul-Masjid (the prayer of salutation to the mosque). Jaabir ibn ‘Abdullaah said: "Sulayk Al-Ghatafaani came on Friday when the Messenger of Allaah was delivering the Khutbah. When he (Sulayk) sat down, the Prophet said to him: "O Sulayk, stand up and observe two Rak’ahs and make them short." [Al-Bukhari and Muslim] This Hadeeth shows that Tahiyyat-ul-Masjid is still required after one’s sitting. Some Muslim jurists held that it is not required after sitting deliberately. The Fatwa we give, however, is that it is still required after sitting and it is permissible for the Muslim to stand up and perform it, even after a long time according to the majority of scholars, based on the Hadeeth mentioned above, whether or not he has an excuse for sitting.
However, it is permissible for the Muslim who enters the Masjid to perform the confirmed Sunnah before Thuhr or any obligatory prayer immediately and it replaces Tahiyyat-ul-Masjid. That is because the point is to perform two Rak’ahs before sitting, and this takes place by performing any two Rak’ahs. For further information, see Fatwa 90142.
Allaah Knows best.