Sayyidina Abdullah ibn Mas’ud (RA) narrated: We asked Allah’s Messenger about walking behind the funeral. He said, “Not more than a trot (that is, walk slower than running). For, if he was pious then you will consign him soon (to the grave) and if he was evil then only the people of the Fire are kept away. The funeral i followed and it does not follow. He who walks in front of it is not of us.”
[Ahmed3734, Abu Dawud 3184, Ibn e Majah 1484]
--------------------------------------------------------------------------------