Language:
كتاب النكاح
67  
Wedlock, Marriage (Nikaah)
(8)
Chapter: What is disliked of not marrying and of getting castrated
(8)
باب مَا يُكْرَهُ مِنَ التَّبَتُّلِ وَالْخِصَاءِ
Sahih al-Bukhari 5075

Narrated 'Abdullah:

We used to participate in the holy battles led by Allah's Messenger (ﷺ) and we had nothing (no wives) with us. So we said, "Shall we get ourselves castrated?" He forbade us that and then allowed us to marry women with a temporary contract (2) and recited to us: -- 'O you who believe ! Make not unlawful the good things which Allah has made lawful for you, but commit no transgression.' (5.87)

حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا جَرِيرٌ، عَنْ إِسْمَاعِيلَ، عَنْ قَيْسٍ، قَالَ قَالَ عَبْدُ اللَّهِ كُنَّا نَغْزُو مَعَ رَسُولِ اللَّهِ صلى الله عليه وسلم وَلَيْسَ لَنَا شَىْءٌ فَقُلْنَا أَلاَ نَسْتَخْصِي فَنَهَانَا عَنْ ذَلِكَ ثُمَّ رَخَّصَ لَنَا أَنْ نَنْكِحَ الْمَرْأَةَ بِالثَّوْبِ، ثُمَّ قَرَأَ عَلَيْنَا ‏{‏يَا أَيُّهَا الَّذِينَ آمَنُوا لاَ تُحَرِّمُوا طَيِّبَاتِ مَا أَحَلَّ اللَّهُ لَكُمْ وَلاَ تَعْتَدُوا إِنَّ اللَّهَ لاَ يُحِبُّ الْمُعْتَدِينَ‏}‏‏.‏
Reference : Sahih al-Bukhari 5075
In-book reference : Book 67, Hadith 13
USC-MSA web (English) reference : Vol. 7, Book 62, Hadith 13
  (deprecated numbering scheme)