The Messenger of Allah –may Allah’s peace and blessings be upon him–, when he entered the mosque, would say: “In the Name of Allah. O Allah, send blessings upon Muḥammad.”
And when he exited, he would say: “In the Name of Allah. O Allah, send blessings upon Muḥammad.”
Narrated by Ibn al-Sunnī in ʿAmal al-Yawm wa al-Laylah (no. 88), from the narration of Anas ibn Mālik –may Allah be pleased with him–.
Authenticated in Ṣaḥīḥ al-Jāmiʿ (no. 4716) and in Takhrīj al-Kalim al-Ṭayyib (no. 64).
Brief Explanation of the Hadith
It was from the guidance of the Prophet –may Allah’s peace and blessings be upon him– to constantly remember Allah in all his situations. As an example was that when he entered the mosque, he would mention the Name of Allah –seeking blessing and assistance– and follow it with invoking prayers upon himself, due to its great virtue and because he –may Allah’s peace and blessings be upon him– was the means for his ummah to attain guidance and reach goodness. The meaning of Allah’s prayers upon His Prophet is His praise of him in the highest assembly and His honoring of him.
Likewise, upon leaving the mosque, he would mention the Name of Allah, then invoke prayers upon himself –so that he would remain in constant connection with his Lord and under His protection and care.
This dhikr is one of the prescribed remembrances when entering and leaving the mosque. Part of perfect emulation of the Prophet –may Allah’s peace and blessings be upon him– is that a Muslim should consistently maintain this remembrance upon entering and leaving the mosque, mindful of the Prophet’s guidance and following his example, seeking acceptance and aspiring for reward.