كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
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 564 a

Jabir reported:

The Messenger of Allah (ﷺ) forbade eating of onions and leek. When we were overpowered by a desire (to eat) we ate them. Upon this he (the Holy Prophet) said: He who eats of this offensive plant must not approach our mosque, for the angels are harmed by the same things as men.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا كَثِيرُ بْنُ هِشَامٍ، عَنْ هِشَامٍ الدَّسْتَوَائِيِّ، عَنْ أَبِي الزُّبَيْرِ، عَنْ جَابِرٍ، قَالَ نَهَى رَسُولُ اللَّهِ صلى الله عليه وسلم عَنْ أَكْلِ الْبَصَلِ وَالْكُرَّاثِ ‏.‏ فَغَلَبَتْنَا الْحَاجَةُ فَأَكَلْنَا مِنْهَا فَقَالَ ‏ "‏ مَنْ أَكَلَ مِنْ هَذِهِ الشَّجَرَةِ الْمُنْتِنَةِ فَلاَ يَقْرَبَنَّ مَسْجِدَنَا فَإِنَّ الْمَلاَئِكَةَ تَأَذَّى مِمَّا يَتَأَذَّى مِنْهُ الإِنْسُ ‏"‏ ‏.‏
Reference : Sahih Muslim 564a
In-book reference : Book 5, Hadith 90
USC-MSA web (English) reference : Book 4, Hadith 1145
  (deprecated numbering scheme)