I can enter buildings and lock zombies out, but sometimes I still continue to get hit like my character is still outside with the zombies. I can loot and do other actions at my actual location, but continue to get hit by zombies as if I was stuck outside with them.
If I stay with-in 20 meters of where the zombies are. I will continue to be hit. I can circle around the building and usually see this generally occurs around entry ways, items like trash-bins, and bushes, as the zombies are circled around those locations hitting at something invisible.