Most scholars are of the opinion that it is permissible to wear shoes in a cemetery. Jarir ibn Hazim said: “I saw al-Hasan and Ibn Sirin walking with their shoes on in a cemetery.” Anas reported: “The Prophet, peace be upon him, said: ‘When a servant of Allah is put into a grave and his companions leave, he can hear the sound of their sandals’.” (Reported by Bukhari, Muslim. Abu Daw’ud, and Nasa’i) The scholars deduce from this hadith that it is permissible to walk in a cemetery with one’s shoes on since the only way the dead would hear the sound of their sandals is when they were wearing them.
Ahmad disliked, however, wearing dyed shoes (Sibtiyah (Arabic), a type of shoes dyed with pods of a species of sant tree) in graveyards. This is based on a report by Abu Daw’ud, Nasa’i, and Ibn Majah from Bushair, the freed slave of the Prophet, peace be upon him, who said: “Once the Prophet, peace be upon him, noticed a man wearing shoes while walking in the cemetery. He said to him: ‘O you who are wearing the sihtiyyah (shoes). Woe to you. Take off your sibtivyah shoes.’ When the man recognized the Messenger of Allah, peace be upon him, he took them off and threw them away.”
Al-Khattabi said: “The order of the Prophet, peace be upon him, may indicate that he disliked this because of the people involved in them. The sibtiyvah shoes were wom by privileged people given to luxury. The Prophet, peace be upon him, liked those visiting the graveyards to be humble and unpretentious. Ahmad holds that wearing shoes is disliked only when done without any valid excuse. If there is a genuine reason for wearing shoes, such as impurities, then one may keep one’s shoes on.