Abu Usaid al-Ansari reported the Messenger of Allah ﷺ as saying: when any of you enters the mosque he should invoke blessing on the prophet ﷺ and then he should say: O Allah, open to me the gates of thy mercy. And when he goes out, he should say: O Allah, I ask thee out of Thine abundance.
Related hadith on this topic
Explanation & Benefits
Hafiz Muhammad Ameen
730. Commentary: When entering, the aim is to attain Allah’s mercy, and upon coming out, one engages in seeking sustenance; therefore, both supplications are appropriate to their respective occasions. By “mercy” is meant blessings of the Hereafter and forgiveness. “Fadl” (bounty) refers to both worldly blessings and sustenance.
Source: Sunan Nasa'i: Translation and Benefits by Shaykh Hafiz Muhammad Amin Hafizullah, Page: 730