The Messenger of Allah ﷺ said, "The rider follows behind the funeral procession, while the one on foot may walk wherever he wishes around it, and the funeral prayer is performed over the infant."
حدثنا عبد الواحد الحداد حدثنا سعيد بن عبيد الله الثقفي عن زياد بن جبير
قال رسول الله ﷺ الراكب خلف الجنازة والماشي حيث شاء منها والطفل يصلى عليه
Its isnad is sahih. Ziyad bin Jubayr bin Hayya Thaqafi is trustworthy, and his hadith is accepted by the whole community of scholars. His father was trustworthy, one of the finest of the Tabiin.The hadith was narrated by Abu Dawud 3/205, no. 3180, in the book of Funerals, chapter on walking in front of the funeral procession, and by Tirmidhi 3/340, no. 1031, in the book of Prayer, chapter on the funeral prayer for children, where he said, hasan sahih, and by Nasai 4/55, no. 1942, in the chapter on the position of the rider in relation to the funeral procession, and by Ibn Majah 1/475, no. 1481, and by Hakim 1/363.