If you find that no one is in, then do not enter unless you have received permission. If you are asked to go away, turn back. That is proper for you. God is aware of what you do.
There is no harm in going into uninhabited houses where there is some convenience for you, as God has knowledge of what you hide and what you disclose.
Tell the believing men to lower their eyes and guard their private parts. There is for them goodness in this. God is aware of what they do.
Tell the believing women to lower their eyes, guard their private parts, and not display their charms except what is apparent outwardly, and cover their bosoms with their veils and not to show their finery except to their husbands or their fathers or fathers-in-law, their sons or step-sons, brothers, or their brothers' and sisters' sons, or their women attendants or captives, or male attendants who do not have any need (for women), or boys not yet aware of sex. They should not walk stamping their feet lest they make known what they hide of their Ornaments. O believers, turn to God, every one of you, so that you may be successful.