Sahih Muslim , Book 16, Hadith 13 (In-Book)

Abdullah (b. Mas'ud) reported: We were on an expedition with Allah's Messenger and we had no women with us. We said: Should we not have ourselves castrated? He (the Holy Prophet) forbade us to do so He then granted us permission that we should contract temporary marriage for a stipulated period giving her a garment, and 'Abdullah then recited this verse: 'Those who believe do not make unlawful the good things which Allah has made lawful for you, and do not transgress. Allah does not like trangressers" (al-Qur'an, v. 87).

حَدَّثَنَا مُحَمَّدُ بْنُ عَبْدِ اللَّهِ بْنِ نُمَيْرٍ الْهَمْدَانِيُّ، حَدَّثَنَا أَبِي وَوَكِيعٌ، وَابْنُ، بِشْرٍ عَنْ إِسْمَاعِيلَ، عَنْ قَيْسٍ، قَالَ سَمِعْتُ عَبْدَ اللَّهِ، يَقُولُ كُنَّا نَغْزُو مَعَ رَسُولِ اللَّهِ صلى الله عليه وسلم لَيْسَ لَنَا نِسَاءٌ فَقُلْنَا أَلاَ نَسْتَخْصِي فَنَهَانَا عَنْ ذَلِكَ ثُمَّ رَخَّصَ لَنَا أَنْ نَنْكِحَ الْمَرْأَةَ بِالثَّوْبِ إِلَى أَجَلٍ ثُمَّ قَرَأَ عَبْدُ اللَّهِ ‏{‏ يَا أَيُّهَا الَّذِينَ آمَنُوا لاَ تُحَرِّمُوا طَيِّبَاتِ مَا أَحَلَّ اللَّهُ لَكُمْ وَلاَ تَعْتَدُوا إِنَّ اللَّهَ لاَ يُحِبُّ الْمُعْتَدِينَ‏}‏ ‏.‏

sunnah.com