You step in a mosque with your right foot. When leaving a mosque you step out with your left foot first.
It is written in Uyûn-ul-basâir: “When entering a mosque, you take off your left and then right shoe before entering. Then you step in with your right foot first. You put on your right shoe after [or before] leaving with your left foot first.”
In explaining the afflictions incurred by hands and feet, the book Hadîqa says, “As imâm-i Nawawî says in his explanation of Muslim, it is mustahab to begin with your right side when doing blessed, honoured and pure deeds. You begin with your right when putting on your shoes, trousers, shirt, when cutting or combing your hair, when trimming your moustache, when using a miswâk, when cutting your nails, when washing your hands and feet, when entering a mosque, a Muslim’s house, a Muslim’s room, when going out of a rest room, when giving alms, when eating, and when drinking.
When doing the opposites of these, for example, when taking off your shoes, socks, clothes, when going out of a mosque, or a Muslim’s house, a Muslim’s room, when entering the restroom, when expelling mucus from your nose, when cleaning yourself after relieving nature, it is mustahab to begin with your left. It is tanzîhî makrûh to do them conversely, because it means to omit the sunnat in hey’et (form).”