The Prophet ﷺ noticed the smell of garlic in the mosque and said, "Whoever has eaten from this foul plant should not come near our mosque."
حدثنا يحيى عن محمد بن عمرو قال حدثني أبو سلمة
وجد النبي ﷺ ريح ثوم في المسجد فقال من أكل من هذه الشجرة الخبيثة فلا يقربن مسجدنا
Its isnad is sahih. Muslim narrated it, 1/394, no. 563, in "Masjids," "The prohibition against one who has eaten garlic or onion." Tirmidhi narrated it, 4/261, no. 1806, in "Foods," "What has been said about the dislike of eating garlic," and he said, hasan sahih. Nasai narrated it, 2/43, no. 707, in "Masjids," "Who is barred from the masjid," from Jabir.Bukhari narrated something similar, 1/216, in "The times of prayer," "What has been said about raw garlic and onion," as did Abu Dawud, 3/361, no. 3825, in "Foods," and Ibn Abu Shayba, 8/115, no. 4537, and Abdul-Razzaq, 1/445, no. 1738.