Sayyiduna Anas bin Malik (may Allah be pleased with him) said that the Prophet of Allah (peace and blessings be upon him) said: "When a servant is placed in his grave and his companions turn back, he hears the sound of their sandals. Two angels come to him and say: 'What do you say about this man?' meaning Muhammad (peace and blessings be upon him)." He said: "If he is a believer, he says: 'I bear witness that he is the slave of Allah and His Messenger.' Then it is said to him: 'Look at your place in the Fire; Allah has exchanged it for you with a place in Paradise.' And he sees them both."
There is also the possibility that he (peace and blessings be upon him) saw filth on the sandals and for that reason ordered that they be taken off, and other possibilities exist as well.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 7217