Mu'awiya said on the authority of his father that God’s Messenger forbade these two plants, i e., onions and garlic, and said, “He who eats them must not come near our mosque.” He also said, “If you must eat them, suppress their odour* by cooking.”
Hakim b. Hizam said that God's Messenger prohibited retaliation being taken in a mosque, the recitation of poems in it, and the infliction of punishment in it.
Abu Dawud in his Sunan and the author of Jami‘ al-usul ( Ibn al-Athir) in his work transmitted it from Hakim, but in al-Masabih it is transmitted from Jabir.
Narrated Abu Huraira reported God’s Messenger as saying:
When you see anyone buying or selling in a mosque, say, “May God not make your trading profitable!” And when you see anyone calling out in it about something lost, say, “May God not restore it to you.”