But they also protect you from more low level lawlessness and if the law situation inside and outside the wall are the same (because of stronger states) they stop being worth maintaining.
Think in the US, the cops wouldn’t survive against a couple of machine guns and a drone strike, but they are still useful for security purposes.
Walls also keep out grazing animals with suicide vests, which is something a friend who served in Afganistan said he saw once.