The following questions were asked of a marja`:
Firstly, what is the ruling in the Revealed Law regarding women entering the masjid in order to take part in lessons on knowledge of the faith or even to just perform the compulsory prayers or optional ones besides?
Secondly, what is the ruling in the Revealed Law regarding children younger than seven years of age entering the masjid along with the fact that they can be disruptive during the prayer in the masjid and also enter the rows of adults and disturb them?
Thirdly, does this happening take away the reward of the prayer in congregation? Does this action affect the validity of the prayer of any individual in the row or does it depend on whether or not the child is a male or female?
The answer given by the marja`, Imam `Abdur-Rahman Ash-Shami, may Allah preserve him, is as follows below:
Women’s entering the masjid in order to be present in gatherings of knowledge of the faith or to perform prayers is permissible as long as they are safe from intermingling with the men and no one causes a spectacle at that time.
As for children entering the masjid, the Hanbali scholars have ruled ruled, “It is Sunnah that the Masjid should be kept clear from any children entering it that have not reached seven years of age.”
So in the case where a child is less than seven years of age and does not know the etiquettes of the masjid, there is no harm in him entering therein while being accompanied by a close relative and he sits the child next to him. The optimum position is that a row of children should be formed behind the men.
If children should come into the rows of the adults, the level of reward for the prayer in congregation is not lost, nor does it lessen. Further to this, a child entering the rows of adults has no effect on the validity of the prayer of any individual in the row, whether the child is a male or female.
 Please see Imam Musa ibn Ahmad Al-Hajjawi’s (d. 968 AH), may Allah be pleased with him, comprehensive work, Al-Iqna` Li-Talib il-Intifa`, vol.1, pp. 68-69 (Riyadh, 1408 AH) where the quote appears.