كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(17)
Chapter: 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
(17)
باب نَهْىِ مَنْ أَكَلَ ثُومًا أَوْ بَصَلاً أَوْ كُرَّاثًا أَوْ نَحْوَهَا عَنْ حُضُورِ الْمَسْجِدِ ‏‏
Sahih Muslim 561 b

Ibn 'Umar reported:

The Messenger of Allah (ﷺ) said: He who eats of this (offensive) plant must not approach our mosque, till its odor dies: (plant signifies) garlic.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا ابْنُ نُمَيْرٍ، ح قَالَ وَحَدَّثَنَا مُحَمَّدُ بْنُ عَبْدِ اللَّهِ بْنِ نُمَيْرٍ، - وَاللَّفْظُ لَهُ - حَدَّثَنَا أَبِي قَالَ، حَدَّثَنَا عُبَيْدُ اللَّهِ، عَنْ نَافِعٍ، عَنِ ابْنِ عُمَرَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ ‏ "‏ مَنْ أَكَلَ مِنْ هَذِهِ الْبَقْلَةِ فَلاَ يَقْرَبَنَّ مَسَاجِدَنَا حَتَّى يَذْهَبَ رِيحُهَا ‏"‏ ‏.‏ يَعْنِي الثُّومَ ‏.‏
Reference : Sahih Muslim 561b
In-book reference : Book 5, Hadith 87
USC-MSA web (English) reference : Book 4, Hadith 1142
  (deprecated numbering scheme)