I heard the Messenger of Allah ﷺ say, "The rider walks behind the funeral procession, and the one on foot may walk wherever he wishes around it."
حدثنا محمد بن بشار حدثنا روح بن عبادة حدثنا سعيد بن عبيد الله بن جبير بن حية حدثني زياد بن جبير بن حية سمع
سمعت رسول الله ﷺ يقول الراكب خلف الجنازة والماشي منها حيث شاء
[Its chain of transmission is hasan] Recorded by Tirmidhi, Book of Funerals, Chapter on the prayer for children, no. 1031, and others, through the route of Saeed, from Ziyad, from his father, from Mughira. Tirmidhi said, hasan sahih. See also Nail al-Maqsud fi Takhrij Sunan Abu Dawud, no. 3180. Ibn Hibban, Hakim, and Dhahabi graded it sahih. See also no. 1507, where there is an addition in its chain.