Sahih Muslim 563
Sahih Muslim · Book 5: The Book of Mosques and Places of Prayer · Prohibiting one who has eaten garlic, onions, or leeks, and other things that have an offensive odor from coming to the masjid, until that smell has gone away, and such a person should be expelled from the masjid
Abu Huraira reported:
وَحَدَّثَنِي مُحَمَّدُ بْنُ رَافِعٍ ، وَعَبْدُ بْنُ حُمَيْدٍ ، قَالَ عَبْدٌ أَخْبَرَنَا وَقَالَ ابْنُ رَافِعٍ، حَدَّثَنَا عَبْدُ الرَّزَّاقِ ، أَخْبَرَنَا مَعْمَرٌ ، عَنِ الزُّهْرِيِّ ، عَنِ ابْنِ الْمُسَيَّبِ ، عَنْ أَبِي هُرَيْرَةَ ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم " مَنْ أَكَلَ مِنْ هَذِهِ الشَّجَرَةِ فَلاَ يَقْرَبَنَّ مَسْجِدَنَا وَلاَ يُؤْذِيَنَّا بِرِيحِ الثُّومِ " .
The Messenger of Allah (ﷺ) said: He who eats of this plant (garlic) should not approach our mosque and should not harm us with the odour of garlic.