There is no blame upon you for entering houses not inhabited in which there is convenience1 for you. And Allāh knows what you reveal and what you conceal.
Translation: Saheeh International (English)
1 Some benefit such as rest, shelter, commodities, one's personal belongings, etc.
There is no blame on you, for entering without permission, public houses which are not specifically for any person and which have been prepared for general benefit, such as libraries and shops in markets. Allah knows the actions and conditions which you display and which you hide; none of that is hidden from Him and He shall reward you for them.