It is narrated from Sayyiduna Jabir (may Allah be pleased with him) that we used to walk in the mosque while in a state of major ritual impurity (janabah), and we did not consider there to be any harm in it.
Hadith Referenceسنن دارمي / من كتاب الطهارة / 1207
Hadith Gradingتحقیق (حسین سلیم أسد الدارانی):إسناده ضعيف لضعف محمد بن أبي ليلى، [مكتبه الشامله نمبر: 1212]
Hadith Takhrijیہ قول ضعیف ہے، محمد بن ابی لیلی اس روایت میں ضعیف ہیں۔ دیکھئے: [مصنف ابن أبى شيبه 146/1] ، [بيهقي 443/2] ، [الدر المنثور 166/2]
Brief Explanation
(Commentary on Ahadith 1202 to 1207) From these narrations, the permissibility of a person in a state of major ritual impurity (junub) passing through the mosque is established. Furthermore, this narration «لَاأُحِلُّالْمَسْجِدَلِجُنُبٍوَلَاحَائِضٍ» is subject to criticism. However, it is not permissible for them to sit in the mosque. And Allah knows best.