I was recently asked regarding the prayer upon entering the Masjid and felt it may benefit others who have questions upon the same topic.
The two rak’ah prayer upon entering the Masjid is know as Tahiyyat al-Masjid (Welcoming the Masjid) it is to be prayed as soon as one enters the masjid or as soon as they are able to (I.e. if they need to make wudhu first). The prayer carries the ruling of Nafl and so one is not sinful if they leave it.
In the Hanafi Madhhab it is not to be prayed if one enter the Masjid during a time in which salah is considered to be Makrooh, that would be, at the time of Sunrise, after praying Asr, and at Sunset, they would also include after one has prayed Fajr.
For the Hanbali school it can be prayed whenever one enters the Masjid even if that is in a Makrooh time, as they consider a specific sunnah which is constricted by time or place or action to take precedence over a general ruling and do they say that the times when salah is makrooh, that is only for general Nafl salah such as salat al-Hajah (the prayer of need) or an unspecified nafl prayer.
The prayer itself is like any other two rak’ah prayer, one makes an intention in their heart to pray two rak’ah nafl for welcoming the Masjid (Tahiyyat al-Masjid) and begins with the openig dua, a recitation of al-Fatihah and then a Surah or portion of al-Quran in both rak’ahs. And the rest is like any other two rak’ah prayer.