The Mosques are houses of worship and it is obligatory to keep them clean and free of filth and noxious smells.
Muslim records that the Prophet sallallahu alehi wasallam said: “These mosques are not meant for urine or filth but they are for the remembrance of Allah and the recital of the Qur’an.
Ahmad records, with a sahih chain, that the Prophet sallallahu alehi wasallam said: “If one of you expectorates, he should cover it lest it should besmear a believer’s body or clothing and harm him.”
Ahmad and al-Bukhari record from Abu Hurairah that the Messenger of Allah said: “When one of you stands to pray, he should not spit in front of him as he is facing Allah when he is in prayer. And he should not spit to his right as there is an angel on his right. So, he should spit to his left or under his feet and he should bury it.”
Jabir reports that the Prophet sallallahu alehi wasallam said: “Whoever eats garlic, onion, or leek should not come close to our mosque for the angels are harmed by what harms the children of Adam.” This is related by al-Bukhari and Muslim.
On Friday, ‘Umar addressed the people saying: “O you people, you eat of two plants which I consider bad [onion and garlic] for I have seen the Prophet, when he perceived their smell from someone, he would order the man to go to al-Baqi’. Whoever eats them should suppress their odour by cooking them.” This is related by Ahmad, Muslim, and an-Nasa’i.