Children in the Masjid
Children who do not know ettiquettes of the Masjid and have no knowledge of ritual cleanliness should NOT be allowed to come to the Masjid. Similarly, children who know ritual cleanliness and also know the sanctity and reverence of the Masjid are permitted to come to the Masjid.
The Holy Prophet (Sallallaahu Alayhi Wasallam) said, 'When the child is seven years old, order him to say prayers and when he is ten years old, CHASTISE HIM TO DO SO.' (Mishkaat). It does not mean that when the child is seven years old, he can pay due respect to the Masjid. The instruction and training for prayer can also be given at home. When a child has attained seven years of age and he can show respect to the Masjid and understand ritual cleanliness, he is permitted to come to the Masjid. There is no prohibition for such a child.
Rasulullah (Sallallaahu Alayhi Wasallam) said, "Keep your insane people and your children away from the Masjid" (Ibn Maajah). This prohibition is generally flouted nowadays where little children create disturbance in the masjid. Often it has been experienced that little children by their crying distract the father and other Musallees as well. The prohibition is based on the sanctity, reverence and cleanliness of the masjid. It is also improper to bring little children into the Saffs (rows) of adults.
and Allah Ta'ala Knows Best
Mufti Ebrahim Desai, www.ask-imam.com