Abdullah ibn Umar, may Allah be pleased with them, said, "The Messenger of Allah, may the peace and blessings of Allah be upon him, said, 'Do not forbid the female slaves of Allah from (going to) the mosques of Allah.' "
Women are the counterparts of men, Allah has ordered them to do what men are commanded to do, except for what one of them can not do, or is not fitting to their situation and status.
The closest position of the slave to his Lord is in his prostration as the Prophet, may the peace and blessings of Allah be upon him, mentioned in the Hadith. Offering the prayer in a congregation is an obligation or a confirmed Sunnah - as some of the scholars mentioned- this ruling is confined to men.
But they may share the men in offering the prayer with them in the mosques, and attend the assemblies of knowledge, provided that they are well covered, not wearing make up or perfume, and that they do not mix with men.
The Prophet, may the peace and blessings of Allah be upon him, forbade husbands, guardians, and others in the same position from forbidding women from going to the mosques as they are female servants of Allah like men are servants to Allah.
This Hadith is a response to those who say that the era and the situation has changed, and corruption has spread, so preventing them from going out to the mosques is a necessity, it is obligatory to keep them in the houses to save them from falling into the sedition, and keeping men safe from falling into temptation.