We used to go on military campaigns with the Messenger of Allah ﷺ without our wives, so we said, "Messenger of Allah, shall we not castrate ourselves?" But he forbade us from doing so.
حدثنا يحيى حدثنا إسماعيل هو ابن أبي خالد حدثني قيس
كنا نغزو مع رسول الله ﷺ ليس لنا نساء فقلنا يا رسول الله ألا نستخصي فنهانا عن ذلك
Its isnad is sahih. Qays is Ibn Abu Hazim Bajali, a senior mukhadram tabii who is trustworthy. Bukhari mentioned his biography in Al-Kabir 4/1/145. The hadith was narrated by the two Shaykhs, as noted in Al-Dhakhair 4812.