We were with the Prophet ﷺ on one of his journeys, and we stopped at a place where garlic grew abundantly. Some of the Muslims ate from it, then came to the prayer area to pray with the Prophet ﷺ. He forbade them from eating it.Later they came again to the prayer area, and he forbade them from it once more. Then they came yet again to the prayer area, and he forbade them from it again. Then they came once more to the prayer area, and he detected its smell on them, so he said, "Whoever eats from this plant must not come near us in our mosque."
حدثنا محمد بن عبد الله بن الزبير حدثنا الحكم بن عطية عن أبي الرباب قال سمعت
كنا مع النبي ﷺ في مسير له فنزلنا في مكان كثير الثوم وإن أناسا من المسلمين أصابوا منه ثم جاءوا إلى المصلى يصلون مع النبي ﷺ فنهاهم عنها ثم جاءوا بعد ذلك إلى المصلى فنهاهم عنها ثم جاءوا بعد ذلك إلى المصلى فنهاهم عنها ثم جاءوا بعد ذلك إلى المصلى فوجد ريحها منهم فقال من أكل من هذه الشجرة فلا يقربنا في مسجدنا
Its isnad is daif. I could not identify Abu Rabab, and perhaps Allah, exalted is He, will make it easy for me to learn who he is. The hadith is sahih and has already appeared at 12872 and 15009 in an abridged form.