I dunno if this might work but maybe you should try building a U shape in stead of just 1 wall. Maybe that might help?
So this works:
If you like to build a wall with a door in front of a mountain it puts the scaff inside if the way into the mountain is only 4 Blocks width. If you make it 6 blocks like in this Pictures it works fine every time: