Abu Hurairah reported,

I said, "Messenger of Allah, I am a young man and I fear that I may fall into sin, yet I cannot find the means to marry."He remained silent. Then I repeated what I had said, and he remained silent. I said it again, and he remained silent. I said it a fourth time, and the Prophet ﷺ replied, "Abu Hurayrah, the pen has dried with what you will encounter, so castrate yourself on that basis or leave it."

Bukhari 5076

Sahih

وقال أصبغ أخبرني ابن وهب عن يونس بن يزيد عن ابن شهاب عن أبي سلمة

عن أبي هريرة رضي الله عنه قال

قلت يا رسول الله إني رجل شاب وأنا أخاف على نفسي العنت ولا أجد ما أتزوج به النساء فسكت عني ثم قلت مثل ذلك فسكت عني ثم قلت مثل ذلك فسكت عني ثم قلت مثل ذلك فقال النبي ﷺ يا أبا هريرة جف القلم بما أنت لاق فاختص على ذلك أو ذر

البخاري 5076صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Marriage
Chapter
What is disliked of celibacy and castration
Numbering
Darussalam 5076
Bukhari 5076