Whenever the Messenger of Allah ﷺ entered the mosque, he would send blessings and peace upon Muhammad and say, "My Lord, forgive me my sins and open for me the gates of Your mercy." And when he left, he would send blessings and peace upon Muhammad and say, "My Lord, forgive me my sins and open for me the gates of Your bounty."
حدثنا علي بن حجر حدثنا إسمعيل بن إبراهيم عن ليث عن عبد الله بن الحسن عن أمه فاطمة بنت الحسين
كان رسول الله ﷺ إذا دخل المسجد صلى على محمد وسلم وقال رب اغفر لي ذنوبي وافتح لي أبواب رحمتك وإذا خرج صلى على محمد وسلم وقال رب اغفر لي ذنوبي وافتح لي أبواب فضلك
Its chain of transmission is daif. Ibn Majah narrated it in "Masajid and Congregations," in the chapter on the supplication when entering the masjid, hadith 771, through the narration of Ismail bin Ulaya, by the same wording. Layth bin Abu Salim is daif with respect to his memory, and the hadith of Muslim, hadith 713b, is sufficient in its place.