The Messenger of Allah ﷺ said, "Teach the child to pray when he is seven years old, and discipline him for neglecting it when he is ten."
حدثنا علي بن حجر أخبرنا حرملة بن عبد العزيز بن الربيع بن سبرة الجهني
قال رسول الله ﷺ علموا الصبي الصلاة ابن سبع سنين واضربوه عليها ابن عشر
Its isnad is hasan. Abu Dawud also narrated it in the Book of Prayer, chapter on when a boy should be commanded to pray, hadith 494, from the hadith of Abdul-Malik with the same wording. Ibn Khuzayma graded it sahih, hadith 1002, as did Ibn Jarud, hadith 147, and Hakim, 1/201, saying it meets the criteria of Muslim, and Dhahabi agreed with him.There is also a hadith on this subject from Abdullah bin Amr [Abu Dawud, hadith 495].