Umm Salamah (may Allah be pleased with her) said: The Prophet (peace and blessings be upon him) came out and turned towards the mosque and said: "Beware! The mosque is not lawful for any man in a state of major impurity (janabah) or any menstruating woman, except for the Messenger of Allah (peace and blessings be upon him), Ali, Fatimah, Hasan and Husayn (may Allah be pleased with them). Beware! I have made the names clear to you so that you do not go astray."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النكاح / 13400
Al-Bukhari (may Allah have mercy on him) said: Mahduj al-Dhuhli from Jasrah, as Ibn Abi Ghaniyyah reported it from Abu al-Khattab; there is reservation about it (fihi nazar).
This has also been narrated through another route from Jasrah, and it contains weakness.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النكاح / 13401
Sayyidah Umm Salamah (may Allah be pleased with her) said that the Messenger of Allah (peace and blessings be upon him) said: "Beware! My mosque is forbidden to every man in a state of major impurity (janabah) and every menstruating woman, except Muhammad (peace and blessings be upon him) and his household: Ali, Fatimah, Hasan and Husayn (may Allah be pleased with them)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النكاح / 13402
It is narrated from Sayyiduna Abu Sa'id (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: "O Ali, it is not lawful for anyone in a state of major impurity (janabah) to be in the mosque except me and you."
Al-Bukhari (may Allah have mercy on him) said about Jasrah's narration of this meaning: This is not authentic from the Prophet (peace and blessings be upon him).
Atiyyah (in this chain) is Ibn Sa'd al-Awfi, and he is not relied upon as evidence.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب النكاح / 13403