Ibn Masud said, "We used to go on military campaigns with the Messenger of Allah ﷺ when we were young men without wives. We asked, 'Messenger of Allah, shall we not castrate ourselves?' But he forbade us from doing so."
كنا نغزو مع رسول الله ﷺ ونحن شباب، وليس لنا نساء، فقلنا: يا رسول الله ألا نستخصي؟ فنهانا عن ذلك.
Ahmad (3706) narrated it from Yazid, who said, Ismail told us, from Qays, from Ibn Masud, and he related it. Muslim (12:1404) also narrated it from Abu Bakr bin Abu Shayba, who said, Waki told us, from Ismail, with his chain of transmission, similarly, except that he did not say in it, "we would raid." It has already been established that the permission came before Khaybar, and this is also indicated by his statement, "we were young men." This may have occurred during the raid on Banu Mustaliq, which took place in the year five of the Hijrah. In that raid the Muslims took much booty and took captives, among whom was Juwayria bint Harith. The Messenger of Allah ﷺ freed her and married her, her emancipation being her dower.Then the prohibition of mutah marriage came at the raid of Khaybar, as is also indicated by the hadiths that follow. However, I have not come across anyone among the biographers who explicitly states this. Suhayli, in Rawd Anf, pointed to the disagreement over the dating of the prohibition of mutah marriage, so refer to it. Yet he did not bring forth any certain report, and the reconciliation he mentioned regarding its prohibition at the raid of Khaybar does not agree with the sahih narrations found in the two Sheikhs. See also Nasb Raya (3/178-179).