Minecraft wiki entry for Structure, associated text: A direction is chosen: up, down, left, right, forward, or back.
If the wall in that direction is already closed, the attempt fails.
The wall is marked as closed.
The two units on either side of the just-closed wall are checked to make sure a path through open walls still exists from each one to the entry unit. If either fails, the wall is re-opened and the attempt fails.