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