From what age one should teach children to pray?
Our children are creatures whose upbringing Allah has entrusted to us and the main task of parents is to teach children what the Almighty has commanded each one of His slaves to fulfill.

To begin this important training, no doubt, one should start with namaz prayer, because in the hadith of the Prophet Muhammad (peace and blessings be upon him) it is said, “Teach a child to pray, begin at the age of seven and punish him for refusing it from the age of ten.” [at-Tirmizi No. 407].
Concerning the instruction of children to pray in “I`anat at-Talibin” the following is written:
“Parents are obligated to command their children, regardless of their sex - male or female - after reaching seven years of age, from the moment they became mumayyiz (i.e. the age at which a child can discern between right and wrong, distinguish between a man and a woman and what to eat and drink), to pray according to all the required conditions, be the prayer performed at the mandatory time or missed.
If a child has no parents, the responsibility rests with the grandfather and grandmother in place of the father or mother or those next of kin who are available. And if there is neither one nor the other, the responsibility to command the performance of namaz passes to the guardian of the child.
If necessary, they should command children to perform prayer and even warn them that they will be punished if they neglect to do so.”
When a child reaches the age of ten, the above mentioned guardians of the child should punish him or her, without causing pain, for a negligent attitude to the obligatory or missed prayer or its conditions.
The reason for this is the authentichadithoftheMessenger of Allah (peace and blessings be upon him): “You command the children to perform namaz when they are seven years old and after reaching ten punish them [for negligence].” [Abu Dawood No. 493]
The wisdom of this attitude is to educate and strengthen in children diligence in worship which will not allow them to forget the skills of worship.
FROM THE BOOK “I’ANAT AT-TALIBIN”, VOL 1, P. 38