The Prophet ﷺ said, "The rider walks behind the funeral procession, while the one on foot may walk wherever he wishes around it, and the funeral prayer is performed over the child."
حدثنا بشر بن آدم ابن بنت أزهر السمان البصري حدثنا إسمعيل بن سعيد بن عبيد الله حدثنا أبي عن زياد بن جبير بن حية عن أبيه
أن النبي ﷺ قال الراكب خلف الجنازة والماشي حيث شاء منها والطفل يصلى عليه
[Its isnad is sahih]. Ibn Majah reported it in the Book of Funerals, chapter on the prayer for a child, no. 1507, and Nasai reported it in 4/56, no. 1945, from the hadith of Saeed bin Ubaydullah, through the same chain. Ibn Hibban graded it sahih (al-Ihsan): 3038, as did al-Hakim: 1/355, and others.