The garlic and onions were mentioned before the Messenger of Allah ﷺ. He was told: The most severe of them is garlic. Would you make it unlawful? The Prophet ﷺ said: Eat it, and he who eats it should not come near this mosque until its odour goes away.
أَنَّهُ ذُكِرَ عِنْدَ رَسُولِ اللَّهِ ﷺ الثُّومُ وَالْبَصَلُ قِيلَ يَا رَسُولَ اللَّهِ وَأَشَدُّ ذَلِكَ كُلِّهِ الثُّومُ أَفَتُحَرِّمُهُ فَقَالَ النَّبِيُّ ﷺ كُلُوهُ وَمَنْ أَكَلَهُ مِنْكُمْ فَلاَ يَقْرَبْ هَذَا الْمَسْجِدَ حَتَّى يَذْهَبَ رِيحُهُ مِنْهُ