1144/1 - Abu Qatādah (may Allah be pleased with him) reported that the Messenger of Allah (may Allah’s peace and blessings be upon him) said: “When anyone of you enters the mosque, he should not sit down until he prays two Rak‘ahs.” [Narrated by Al-Bukhāri and Muslim]
1145/2 - Jābir (may Allah be pleased with him) reported: I came to the Prophet (may Allah’s peace and blessings be upon him) while he was in the mosque, so he said: “Pray two Rak‘ahs.” [Narrated by Al-Bukhāri and Muslim]
1) The greeting of the mosque is a strongly confirmed Sunnah. It is to be prayed whenever a person enters the mosque and intends to sit down.
2) The purpose of the greeting of the mosque is to begin your stay in the mosque with a prayer, be it a Rawātib Sunnah, a Sunnah of ablution, or an obligatory prayer performed in congregation.
3) By legislating the greeting of the mosque, the Shariah shows reverence to the houses of Allah and their sacredness.