The Messenger of Allah ﷺ said, "Whoever lifts a curtain and lets his gaze enter a house before being granted permission, and thereby sees the private parts of its people, has committed a transgression that was not lawful for him to commit. If, the moment he cast his gaze inside, a man had confronted him and gouged out his eyes, I would not blame him for it. But if a man passes by a door that has no curtain and is not shut, and he looks inside, there is no sin upon him. The sin lies upon the people of the house."
حدثنا قتيبة حدثنا ابن لهيعة عن عبيد الله بن أبي جعفر عن أبي عبد الرحمن الحبلي
قال رسول الله ﷺ من كشف سترا فأدخل بصره في البيت قبل أن يؤذن له فرأى عورة أهله فقد أتى حدا لا يحل له أن يأتيه لو أنه حين أدخل بصره استقبله رجل ففقأ عينيه ما عيرت عليه وإن مر الرجل على باب لا ستر له غير مغلق فنظر فلا خطيئة عليه إنما الخطيئة على أهل البيت
[Its chain of transmission is daif] Ahmad reported it (5/153) from the hadith of Ibn Lahia through the same route, and he used "an" (indicating a possible break in transmission).There is also a narration on this topic from Abu Hurairah [Bukhari, no. 6902, Muslim, no. 2158, and Abu Dawud, nos. 5172, 5173] and from Abu Umama [Ahmad, 5/250, 260, 261].