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.
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.