The command to children regarding prayer is for the sake of training, not obligation, because children are not held accountable until puberty.
➊ It is narrated from Amr ibn Shu’ayb, from his father, from his grandfather, that the Messenger of Allah ﷺ said:
مروا صبيانكم بالصلاة لسبع سنين واضـر بـو هــم عليـهـا لعشر سنين
“Command your children to pray when they are seven years old, and when they reach ten years old, beat them for neglecting it.”
➋ It is narrated from Aisha (may Allah be pleased with her) that the Prophet ﷺ said:
ورفع القلم عن ثلاثة عن النائم حتى يستيقظ وعن الصبى حتى يحتلم وعن المجنون حتي يعقل
“The pen (of recording sins) has been lifted from three: from the sleeper until he wakes up, from the child until he reaches puberty, and from the insane person until he becomes sensible.”