Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) used to permit a person in a state of major impurity to pass through the mosque, and he would say concerning "Nor when in a state of major impurity, except when passing through" [Surah al-Nisa: 43]: What I know is that a person in a state of major impurity should not approach the prayer, except a traveller.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4327