There is a clear tradition of the Prophet (peace be upon him) encouraging women to offer their prayers inside their houses : "The best mosques for women are the inner parts of their houses"
Since the Prophet had not forbidden women to attend the mosques, they continued to come to the mosques. But after his death it became increasingly clear that it was not keeping with the dignity and honour of Muslim women to come to the mosques for prayers, especially at night, because men, being what they were, would tease them. Therefore, the Khalif Umar told women not to come to the mosques, but to offer their prayers inside their own houses. The women of Madina resented this prohibition and complained to Aisha. But they received a fitting reply from her : "If the Prophet knew what Umar knows, he would not have granted you permission to go out (to the mosque)".
It is reported by Abu Hurairah that the Prophet (peace be upon him) said, "The best row for men is the first, and the worst for them is the last. The best row for women is the last, and the worst is the first."