The issue of women not being allowed to stay in the mosque is not based on precaution and it's not specific to women only rather anyone who is either in haydh or junub therefore a man who has not done his ghusl e janabat equally cannot stay in the mosque.
Furthermore the doors of Allah are not closed on anyone in any state and rather it is recommended for a woman in haydh to do wudhu and sit on her prayer mat and do tasbeeh, duas etc.