It is narrated from Ibn Abbas (may Allah be pleased with them both) who states: "I came riding on a donkey, and at that time I was close to reaching puberty, and the Messenger of Allah (ﷺ) was leading the people in prayer. I passed in front of the row, dismounted, and let the donkey graze, and then joined the row (of worshippers). No one objected to me for this."
Hadith Referenceمسند الإمام الشافعي / كتاب الصلاة / 184
Hadith Takhrijأخرجہ البخاری: العلم، باب متٰی یصح سماع الصغیر: 76، ومسلم، الصلاۃ، باب سترۃ المصلی والندب الٰی الصلاۃ... الخ: 504۔