It is sunnah to make supplications while going to the mosque. The following are examples of such supplications:
Umm Salamah reports: “When the Messenger of Allah left the house he would say: ‘In the name of Allah, I put my trust in Allah. O Allah, I seek refuge in Thee lest I stray or be led astray or cause injustice or suffer injustice or do wrong or have wrong done to me !” This is related by Abu Dawud, an-Nasa’i, Ibn Majah, and at-Tirmizhi, who calls it sahih.
Anas reports that the Messenger of Allah said: “Whoever says upon leaving from his house: ‘In the name of Allah, I put my trust in Allah. There is no power or might except with Allah,’ it will be said to him: ‘That is sufficient for you…you are guided, defended, and protected and the devil will be driven away from you.”‘ This is related by Abu Dawud, an-Nasa’i, and at-Tirmizhi who calls it hasan.
Al-Bukhari and Muslim record from Ibn ‘Abbas that the Prophet left for the mosque saying: “O Allah, make light in my heart, and light in my vision, and light in my hearing, and light on my right, and light behind me, and light in my nerves, and light in my flesh, and light in my blood, and light in my hair and light in my skin.”
In Muslim’s version, we findÂ “O Allah, make light in my heart and light on my tongue, and make light in my hearing, and light in my sight, and make light behind me, and light in front of me, and make light above me, and light below me. O Allah, give me light.”
Abu Sa’id al-Khudri reports that the Prophet said: “If a man leaves his house to go to the prayer and says, ‘O Allah, I ask You by the right of the suppliant upon You and by the right of this walking – as I have not come out in an arrogant or unthankful manner or for show or for fame; I came out in fear of Your anger and desiring Your pleasure – I ask You to rescue me from the Fire and to forgive my sins as no one forgives sins, save You,” Allah will assign for him seventy thousand angels to ask forgiveness for him and Allah turns His face to him until he finishes his prayer.” This is related by Ahmad, Ibn Khuzaimah, and Ibn Majah. Al-Hafez said that it is hasan.