Sahl bin Saad reported,

A man peeked through a hole into the Prophet's ﷺ room while the Prophet ﷺ had a comb with which he was scratching his head. He said, "If I had known you were looking, I would have struck your eye with it. Permission to enter was prescribed only because of the gaze."

Azami 14188

Sahih

عن سهل بن سعد، قال

اطلع رجل من جحر في حجر النبي ﷺ، ومع النبي ﷺ مدرى يحك به رأسه، فقال: لو أعلم أنك تنظر، لطعنت به في عينك، إنما جعل الاستئذان من أجل البصر.

الأعظمي 14188صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Superior moral conduct
Chapter
Etiquette of seeking permission and greetings
Section
Seeking permission because of sight
Numbering
Jami al-Kamil 14188 (2nd edition)
Azami 14188