It used to be that if two countries shared a border, they needed to have roughly equal military strength on that border, or the stronger one would invade the weaker as a matter of course. This was the obvious and normal way of things, for centuries. If you had the power to invade a neighbour with impunity, then that's what you did.
Then there was a big war. At the time, it was called "The Great War", and was described as "the war to end all wars". It didn't quite live up to that billing; indeed, twenty years later, they had a reunion and did the whole thing over - at which point the two periods of fighting became known as "World War I" and "World War II".
The first world war may not have ended all wars, but it did teach most of the Great Powers that the old system of invading anyone weaker that oneself was a poor idea - modern weapons and tactics made even a successful invasion of another Great Power too costly to bother with.
Some of the Great Powers were slow learners, and had to have a do-over before realising that this wasn't solely an effect of getting bogged down in a static defensive conflict until one side ran out of shells, food, and troops; It proved to also be true of a "lightning war" in which armour and air power allowed rapid movement of attacking forces.
Basically, in the first half of the twentieth century, weapons became sufficiently powerful that winning a war cost more than not having one at all, at least for major powers. Small colonial wars against poorly armed people a long way from your borders are still fairly attractive, but even a little bit of war at home is now too much to be worth the cost.
Mexico would lose a war against the USA in short order; But the US wouldn't get off without some serious damage to people and property inside the US itself. That's going to lose a lot of votes for whichever party decides to invade across the Rio Grande.
Shit, Americans have no tolerance for even a small terrorist attack on their own soil - 9/11 caused the entire nation to collectively lose their shit over three buildings being hit. They wouldn't be sanguine about the retreating Mexican defenders shelling US border cities and towns into rubble, even if the Mexicans were bombed back to the paleolithic immediately thereafter.