وعن عمر بن الخطاب - رضي الله عنه: أنَّه خَطَبَ يومَ الجُمُعَةِ فَقَالَ في خطبته: ثُمَّ إنَّكُمْ أَيُّهَا النَّاسُ تَأكُلُونَ شَجَرتَيْنِ مَا أرَاهُمَا إِلاَّ خَبِيثَتَيْن: البَصَلَ، وَالثُّومَ. لَقَدْ رَأَيْتُ رسولَ الله - صلى الله عليه وسلم - إِذَا وَجدَ ريحَهُمَا مِنَ الرَّجُلِ في المَسْجِدِ أَمَرَ بِهِ، فَأُخْرِجَ إِلَى البَقِيعِ، فَمَنْ أكَلَهُمَا، فَلْيُمِتْهُمَا طَبْخًا. رواه مسلم.
It is narrated from Sayyiduna Umar bin al-Khattab (may Allah be pleased with him) that he delivered the sermon on Friday and said in his sermon: Then, O people, you eat two plants which I consider nothing but foul (foul-smelling): onion and garlic. I saw the Messenger of Allah (peace and blessings be upon him), when he noticed their smell on a man in the mosque, give an order concerning him, and he would be taken out to al-Baqi'. So whoever eats them, let him kill (their smell) by cooking them.
(Narrated by Muslim)
Brief Explanation
Shaykh Ibn Uthaymin (may Allah have mercy on him) says: "Onion and garlic are not forbidden; it is permissible for a person to eat them. But when he eats them, he should not enter the mosque, nor pray with the congregation, nor attend a lesson of knowledge, because the angels are harmed by its foul smell." (Sharh Riyad al-Salihin by Ibn Uthaymin 4/291-292)