As for her going out to the mosque in order to pray with the Muslims—whether for an obligatory prayer, the tarawīḥ and tahajjud in Ramadan, the ʿEid prayer, the prayer for rain (ṣalāt al-istisqāʾ), the Friday prayer, or to attend religious lessons from which she can benefit—there is nothing wrong with it. The Prophet (peace and blessings be upon him) said, “Do not prevent the female servants of Allah from the mosques of Allah,” provided that her outing is in the manner of covering and modesty we have already described.
Accordingly, her husband has no right to stop her so long as she observes that modesty and concealment and her intention is good, for the Prophet (peace and blessings be upon him) said, “Do not prevent the female servants of Allah from the mosques of Allah.” However, if she violates the Islamic code of conduct and her husband notices it, he may forbid her. This conforms to the statement of ʿĀ’ishah (may Allah be pleased with her): “Had the Messenger of Allah (peace and blessings be upon him) seen what the women have introduced, he would have forbidden them from the mosques just as the Children of Israel forbade their women,” or words to that effect.
The reason is that when a woman behaves improperly—failing to maintain proper covering and modesty—she must be barred from the mosques, and likewise from other public places, and required to stay in the home to safeguard and protect her. The same applies if her going out would harm her young children who need her presence and supervision; in that case, the husband is likewise justified in preventing her for their sake. And Allah, the Exalted, knows best.