Shutting every door behind you while you loot a building will give the illusion to other players who come into the same building after you that no one has been in the building yet, thus creating a false sense of safety. Meanwhile, you're waiting for the player to cross your weapon's sights as they roam around the building as if no one else was inside.
You don't necessarily need to close doors when you're leaving a building.