One of the conditions which must be met before starting to pray is to make sure that one's body and clothes and the place in which the Muslim is going to pray are all clean and free of impurities. It was narrated from the Prophet (peace and blessings of Allaah be upon him) that he used to pray wearing his shoes. Anas ibn Maalik (may Allaah be pleased with him) was asked, “Did the Prophet (peace and blessings of Allaah be upon him) pray wearing shoes?” He said, “Yes.” (al-Bukhaari, 386; Muslim, 555). This is to be understood as meaning, so long as there is no impurity on the shoes; if there is any impurity on them then it is not permissible to pray in them. If a person forgets and prays wearing shoes when there is some impurity on them, then he has to take them off when he finds out or remembers. This is because of the hadeeth of Abu Sa’eed al-Khudri who said: “While the Messenger of Allaah (peace and blessings of Allaah be upon him) was leading his companions in prayer, he took off his shoes and placed them to his left. When the people saw that, they took off their shoes too. When the Messenger of Allaah (peace and blessings of Allaah be upon him) finished his prayer, he asked, ‘What made you take off your shoes?’ They said, ‘We saw you take off your shoes, so we took ours off too.’ The Messenger of Allaah (peace and blessings of Allaah be upon him) said, ‘Jibreel (peace be upon him) came to me and told me that there was something dirty on them.’ When any one of you comes to the mosque, let him look and if he sees anything dirty on his shoes, let him wipe them and then pray in them.” (Abu Dawood, 650; classed as saheeh by al-Albaani in Saheeh Abi Dawood, 605).
One of the reasons why the Prophet (peace and blessings of Allaah be upon him) prayed wearing shoes is to be found in the hadeeth, “Be different from the Jews, who do not pray in their shoes or in their leather slippers (khufoof).” (Abu Dawood, 652; classed as saheeh by al-Albaani in Saheeh Abi Dawood, 607). That is regarded as mustahabb for the purpose of differing from non-Muslims, as stated above.
This has to do with the kind of shoes and with the mosque at that time. However if the mosque is furnished with carpeting, then the mosque should be kept clean of shoes, and no one should enter wearing shoes lest the place be made dirty. (Fataawa Samaahat al-Shaykh ‘Abd-Allaah ibn Humayd, p. 81). Moreover the furnishings of the mosque are a waqf which should not be damaged or destroyed, and if dirt gets onto the carpets it will offend those who pray and prostrate on them. Hence no one should enter wearing shoes and walk on the carpets in the mosque in shoes, lest he damage them or make them dirty.
The one who is keen to follow this Sunnah can apply it when praying at home, or when praying in places where there are no furnishings or carpets, such as parks, beaches and out of doors, etc. If this action confuses some of those who are unaware of the Sunnah, he should explain to them that it is Sunnah before he does it, so that they will not find that odd. We ask Allaah to make us among those who adhere to the Sunnah and strive to follow it until He joins us with the author of the Sunnah (peace and blessings of Allaah be upon him) close to the Lord of the Worlds. And Allaah is the Source of strength.