It is narrated that ‘Aa’ishah (may Allah be pleased with her) said: The Messenger of Allah (blessings and peace of Allah be upon him) asked me to hand him something from the mosque and I said: I am menstruating. He said: “Your menstruation is not in your hand.” I hope you can explain this hadeeth; does it mean that the menstruating woman cannot enter the mosque or do anything?.
The Prophet (blessings and peace of Allah be upon him) said: “I do not permit a menstruating woman or a person who is junub to enter the mosque.” And Allah, may He be exalted, says (interpretation of the meaning): “O you who believe! Approach not As‑Salaah (the prayer) when you are in a drunken state until you know (the meaning) of what you utter, nor when you are in a state of Janaaba (i.e. in a state of sexual impurity and have not yet taken a bath), except when travelling on the road (without enough water, or just passing through a mosque), till you wash your whole body” [al-Nisa’ 4:43]. An exception is made for people who are junub who are just passing through, and the same applies to menstruating women. The menstruating woman should not sit in the mosque, but she may pass through. There is nothing wrong with one who is passing through going from one door to another, or going in to get something from the mosque, such as a small mat or a book or a vessel and so on. When the Prophet (blessings and peace of Allah be upon him) told ‘Aa’ishah to hand him a small mat -- referring to a prayer mat made of papyrus on which he (blessings and peace of Allah be upon him) used to pray -- she told him that she was menstruating, and he said to her: “Your menstruation is not in your hand.” What is meant is that there is nothing to prevent her going into the mosque to get something; rather what is forbidden is for her to sit in the mosque. As for her passing through or going to get something, there is nothing wrong with that, and this hadeeth indicates that. End quote.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allah have mercy on him).