Door locks prevent the casual burglar, not the person determined to get in.
The people coming across the border didn't just happen by the border one day and said, "Oh look it's open, let's go in." No, they usually travel a long distance under a variety of hardships. When they get to the border, the reaction will not be, "Oh, a wall, let's give up now." It will be, "Oh, another obstacle, let's figure out a way to get through it." And they will unless the wall is manned at enormous expense.
The amount you spend on security is determined by the value of what you are trying to protect. Which is why the whole thing is a political, not an engineering question.
What's a border worth? Tie it to concerns about national integrity and the value goes up. Not bothered by unauthorized immigration? Then the value goes down.