Al-Mughirah bin Shu'bah said:
"I heard the Messenger of Allah(ﷺ)say: 'The rider should travel behind the funeral (procession)but theone who is walking may walk wherever he wants." (JA)
English reference (JA): Vol. 1, Book 6, Hadith 1481 (JA)
Arabic reference (JA): Book 6, Hadith 1548 (JA)