Abdullah bin Masud reported,

We used to go on military expeditions with the Messenger of Allah ﷺ, and our time away from our wives would grow long. We asked, "Messenger of Allah, should we not castrate ourselves?" He forbade us from doing so, then he permitted us to marry a woman for a fixed term in exchange for something. Later he prohibited that for us on the day of Khaybar, along with the flesh of domesticated donkeys.

Azami 6460

Sahih

عن ابن مسعود قال

كنا نغزو مع رسول الله ﷺ فتطول غربتنا. فقلنا: ألا نستخصى يا رسول الله! فنهانا، ثم رخص أن نتزوج المرأة إلى أجل بالشيء، ثم نهانا عنها يوم خيبر، وعن لحوم الحمر الأهلية.

الأعظمي 6460صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Marriage
Chapter
Prohibited marriages in Islam
Section
Mutah marriage and the explanation of its abrogation
Numbering
Jami al-Kamil 6460 (2nd edition)
Azami 6460