When you place a building or a wall in your village, there is a safe zone around it appearing in white.This zone changes to red when you attack another player. No troop can be deployed inside this zone, but if you place the walls too far away from the buildings, troops can attack from inside the gaps between the walls and the buildings (see image below).
Remember that
Traps, Bombs, Hidden Teslas and decorations do not have a safe zone: if you place them too far from other buildings or walls, they will create empty spaces in your village allowing enemies to deploy their troops on it.