When attached to a wall, it should auto-snap. If it's snapping to the wrong wall, remove the one it's snapping to, place the gate, and then re-add the removed wall.
Should it matter where the wall is? It won't let me setup a gate on my land's perimeter facing the river, but it will allow me to facing the Alliance Gate.