For a long time the US had "open borders" so long as certain groups (demographics) were the main ones profiting off of the US being a capitalist Nation, and minority groups were legally subjugated. Mexicans always lived in the West because it literally was Mexico, colonized largely by Spain. Hence the States that have Spanish names. Though over time we called many of these Mexicans "Indians" as a differentiation for when we drew the line on the map and pushed the notion of "Mexican" South of what's now the Western United States. It was when Southern Europeans started to arrive that the first immigration quotas popped up as Federal policies. Prior to that you had more local things like anti-Chinese groups who wanted workers from China minus the same legal protections as black workers.
That only worked for so long until the. majority demographic kind of assimilated even the Southern Europeans and the main shift of immigration limitation became aimed at Mexicans, Central, and South Americans. Before xenophobia became a political cudgel as potent as it is now, the response to undocumented immigration was generally to make it documented. Capitalists liked this because it created a market for cheap labor. Hence why staunch conservatives under Reagan were still fairly supportive of amnesty. Over time US conservatives soured on this and saw a means to sew greater divide between working class people the same way creating tiered employee ranks does in large workplaces. Then they convinced the "real" Americans that the "illegals" are getting popcorn, free cars, desserts, and trips to Disney World, while the "real" Americans have to work 14hr shifts and pay tens of thousands of dollars for healthcare.
The reason entering the US "illegally" is a Civil Infraction (which means NON-criminal), is because its understood that moving from one place to another place across an arbitrary line in the sand isnt inherently harmful to anyone. A kid walking through your yard is no specific threat to you, thus, there are legal steps to making that a criminal offense. And those steps are less easy when you're referring to public land.
The idea that a human being, in some random place on the earth, is "illegal" is an aspect of dominion ideology disguised as policy. In a World without these absurd ideologies, I could move to and work in any Country I damn well please so long as I'm not harming people, and if I do I'm subject to the laws. And I'm free to do this with minimal barriers of entry. Hyper-nationalism turns a Nations into a gaggle of xenophobes who constantly consume news validating their prejudices, and vote for isolationist/protectionist leaders thirsty for power. Good way to get a North Korea of the West.