Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:24:28

And if you do not find anyone therein, do not enter them until permission has been given you. And if it is said to you, "Go back," then go back; it is purer for you. And Allah is Knowing of what you do.  

And if you do not find anyone in them, to give you permission, ˹still˺ do not enter them until permission has been given to you. And if it is said to you, when you are seeking permission, ‘Go away,’ then go away, for this, going away, is purer, that is, better, for you, than sitting ˹and waiting˺ at the doorstep. And God knows what you do, whether you enter with permission or without it, and He will requite you for it.
القرآن:٢٤:٢٨

فَإِنْ لَمْ تَجِدُوا فِيهَا أَحَدًا فَلَا تَدْخُلُوهَا حَتَّىٰ يُؤْذَنَ لَكُمْ ۖ وَإِنْ قِيلَ لَكُمُ ارْجِعُوا فَارْجِعُوا ۖ هُوَ أَزْكَىٰ لَكُمْ ۚ وَاللَّهُ بِمَا تَعْمَلُونَ عَلِيمٌ  

{فإن لم تجدوا فيها أحدا} يأذن لكم {فلا تدخلوها حتى يؤذن لكم وإن قيل لكم} بعد الاستئذان {ارجعوا فارجعوا هو} أي الرجوع {أزكى} أي خير {لكم} من القعود على الباب {والله بما تعملون} من الدخول بإذن وغير إذن {عليم} فيجازيكم عليه.