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:29

There is no blame upon you for entering houses not inhabited in which there is convenience for you. And Allah knows what you reveal and what you conceal.  

You would not be at fault if you enter ˹without permission˺ uninhabited houses wherein is comfort, some benefit, for you, in the way of finding shelter and so on, as in the case of travellers inns and charitable hostels. And God knows what you disclose, ˹what˺ you do openly, and what you hide, what you do secretly when entering houses other than your own, be it for a righteous purpose or otherwise. It will be mentioned shortly that they should bid themselves peace when entering their own houses.
القرآن:٢٤:٢٩

لَيْسَ عَلَيْكُمْ جُنَاحٌ أَنْ تَدْخُلُوا بُيُوتًا غَيْرَ مَسْكُونَةٍ فِيهَا مَتَاعٌ لَكُمْ ۚ وَاللَّهُ يَعْلَمُ مَا تُبْدُونَ وَمَا تَكْتُمُونَ  

{ليس عليكم جناح أن تدخلوا بيوتا غير مسكونة فيها متاعٌ} أي منفعة {لكم} باستكنان وغيره كبيوت الربط والخانات المسبلة {والله يعلم ما تبدون} تظهرون {وما تكتمون} تخفون في دخول غير بيوتكم من قصد صلاح أو غيره، وسيأتي أنهم إذا دخلوا بيوتهم يسلمون على أنفسهم.