I was walking with the Messenger of Allah ﷺ when he passed by the graves of the Muslims. He said, "These have been spared much evil."Then he passed by the graves of the polytheists and said, "These have missed out on much good."Then he happened to glance aside and saw a man walking among the graves wearing his sandals. He called out, "You there, wearing the leather sandals, take them off!"
أخبرنا محمد بن عبد الله بن المبارك قال حدثنا وكيع عن الأسود بن شيبان وكان ثقة عن خالد بن سمير عن بشير بن نهيك أن
كنت أمشي مع رسول الله ﷺ فمر على قبور المسلمين فقال لقد سبق هؤلاء شرا كثيرا ثم مر على قبور المشركين فقال لقد سبق هؤلاء خيرا كثيرا فحانت منه التفاتة فرأى رجلا يمشي بين القبور في نعليه فقال يا صاحب السبتيتين ألقهما
[Its chain of transmission is sahih]. Ibn Majah collected it in the Book of Funerals, Chapter on What Has Been Said About Taking Off Sandals in Graveyards, no. 1568, from the hadith of Waki bin Jarrah, narrated through him, and it is also found in Sunan al-Kubra, no. 2175. Ibn Hibban, Hakim, and Dhahabi graded it sahih. Abu Dawud collected it, no. 3230, from the hadith of Aswad bin Shayban, narrated through him.