Riyad as-Salihin (The Meadows of the Righteous)
by Imam Nawawi
311. Chapter: On the prohibition against entering the mosque for the one who eats eating garlic, onions, leeks, and other things which have an objectionable smell until its smell departs, except in case of necessity
1701. Ibn 'Umar reported that the Prophet, may Allah bless him and grant him peace, said during the expedition to Khaybar, "Anyone who eats any of this plant, i.e. garlic, should not come near our mosque." [Agreed upon]
In a variant of Muslim, "our mosques."
1703. Jabir reported that the Messenger of Allah, may Allah bless him and grant him peace, said, "Anyone who eats garlic and onions should keep away from us (or he said, "should keep away from our mosque") [Agreed upon]
1704. 'Umar ibn al-Khattab reported that on the Day of Jumu'a he gave an address in which he said, "Then you, O people, eat two plants which I only see as having a foul smell: onions and garlic. I saw that when Messenger of Allah, may Allah bless him and grant him peace, smelt them coming from a man in the mosque, he commanded him to go out, and he was taken out to al-Baqi'. Anyone who eats them should kill them through cooking." [Muslim]