This is a NAFL (optional) Salat, a highly recommended prayer consisting of two Raka'ahs and performed when first entering a mosque. It is considered to be a way of greeting the place of worship in order to draw nearer to Allah.
The Prophet of Allah (peace be upon him) used to pray whenever he used to go in the Mosque (Masjid).
The Prophet Muhammad (peace be upon him) said:
'If any of you enters the Mosque, let him not sit until he prays two rakats."
[Bukhari & Muslim]
And on the authority of Abu Dhar (Allah be pleased with him) he said,
"I entered the mosque, and there was the Messenger of Allah (Allah bless him and give him peace) sitting alone, so he (peace be upon him) said:
"Oh Abu Dhar, Truly the mosque has a greeting, and indeed its greeting is two rakats, so stand up and pray them."
[Reported by Ibn Hiban in his Sahih]