Abu Saeed Khudri reported,

No sooner had Khaybar been conquered than we, the companions of the Messenger of Allah ﷺ, fell upon that vegetable, garlic, for the people were hungry, and we ate a great deal of it. Then we went off to the mosque, and the Messenger of Allah ﷺ caught the smell.He said, "Whoever has eaten anything of this foul plant should not come near our mosque."The people said, "It has been forbidden, it has been forbidden!"Word of this reached the Prophet ﷺ, so he said, "People, it is not for me to forbid what Allah has made lawful for me, but it is a plant whose smell I find unpleasant."

Azami 3148

Sahih

عن أبي سعيد قال

لم نعد أن فتحت خيبر، فوقعنا أصحاب رسول الله ﷺ في تلك البقلة الثوم. والناس جياع، فأكلنا منها أكلا شديدا، ثم رحنا إلى المسجد فوجد رسول الله ﷺ لريح. فقال: من أكل من هذه الشجرة الخبيثة شيئا فلا يقربنا المسجد فقال الناس: حرمت حرمت، فبلغ ذك النبي ﷺ فقال: أيها الناس! إنه ليس لي تحريم ما أحل الله لي ولكنها شجرة أكره ريحها.

الأعظمي 3148صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Mosques
Section
Prohibition of coming to the mosques after eating garlic, onions, and leeks
Numbering
Jami al-Kamil 3148 (2nd edition)