Fiqh-us-Sunnah Volume 2, Supererogatory Prayer, Fiqh 2.069.
Section : Supplications upon entering and leaving the mosques.
It is a sunnah for one who wants to enter the mosque to enter with his right foot first and to say: “I seek refuge in Allah, the Exalted, and by His honorable face, and in His everlasting authority, [away] from the outcast Satan. In the name of Allah! O Allah, shower blessings upon Muhammad. O Allah, forgive my sins for me and open for me the doors of Your mercy.”
When one wants to leave the mosque he should step with his left foot first and say: “In the name of Allah! O Allah, shower blessings upon Muhammad. O Allah, forgive my sins for me and open for me the doors of Your bounty. O Allah, protect me from the accursed Satan.”