1701/1 - Ibn ‘Umar (may Allah be pleased with him and his father) reported that the Prophet (may Allah’s peace and blessings be upon him) said: “He who has eaten from this tree - meaning garlic - should not approach this mosque of ours.” [Narrated by Al-Bukhāri and Muslim]
Another narration by Muslim reads: “our mosques”.
1702/2 - Anas (may Allah be pleased with him) reported that the Prophet (may Allah’s peace and blessings be upon him) said: “He who has eaten from this tree should not approach us or pray along with us.” [Narrated by Al-Bukhāri and Muslim]
1703/3 - Jābir (may Allah be pleased with him) reported that the Prophet (may Allah’s peace and blessings be upon him) said: “He who has eaten garlic or onions should keep away from us - or from our mosque.” [Narrated by Al-Bukhāri and Muslim]
Another narration by Muslim reads: “He who has eaten onions, garlic, or leek should not approach our mosque, for the angels get annoyed by what humans get annoyed by.”
1704/4 - ‘Umar ibn al-Khattāb (may Allah be pleased with him) delivered a Friday sermon one day and said in it: “O people, you eat two plants that I only find offensive: onion and garlic. I saw the Messenger of Allah (may Allah’s peace and blessings be upon him) when detecting their odor on a man in the mosque, he would order that he should be taken out to Al-Baqī‘. So, anyone who wants to eat them should eliminate their odor by cooking.” [Narrated by Muslim]
--
1) It is prohibited to go to the mosque after eating garlic, onions, or the like of such plants that have a bad odor.
2) Angels get annoyed by what annoys humans. So, a Muslim should be good-smelling, especially in places of worship and Muslim gatherings; most notable among them is prayer and learning classes.
It is permissible to eat onions and garlic. Yet, he who has eaten any of them should avoid going to the mosque to attend the congregational prayer. However, if he uses some substance that removes the bad odor, then he can go to the mosque. But it is not permissible for a person to intentionally eat onions or garlic to skip the congregational prayer in the mosque.