The Messenger of Allah ﷺ was leading the prayer when he removed his sandals, so the people removed their sandals as well. When he finished, he asked, "Why did you remove your sandals?"They replied, "Messenger of Allah, we saw you remove yours, so we removed ours."He said, "Jibreel came to me and informed me that there was filth on them. So when one of you comes to the mosque, let him turn his sandal over and inspect it. If he sees any filth on it, let him wipe it against the ground, then pray in them."
حدثنا يزيد أخبرنا حماد بن سلمة عن أبي نعامة عن أبي نضرة
أن رسول الله ﷺ صلى فخلع نعليه فخلع الناس نعالهم فلما انصرف قال لم خلعتم نعالكم فقالوا يا رسول الله رأيناك خلعت فخلعنا قال إن جبريل أتاني فأخبرني أن بهما خبثا فإذا جاء أحدكم المسجد فليقلب نعله فلينظر فيها فإن رأى بها خبثا فليمسه بالأرض ثم ليصل فيهما
Its isnad is sahih. Abu Numama, who is Hanafi Qays bin Ubaya, is trustworthy. The hadith was narrated by Abu Dawud 1/175 no. 650, in the chapter on Prayer, Praying in Sandals, and by Ibn Khuzayma 2/107 no. 1017, and by Hakim 1/260, and Dhahabi agreed with him.