Because they're not all Mexicans by and large, but people fleeing the sociopolitical disasters in their home countries in South and Central America.
That's certainly the logic the USA and other countries applied to the MS St. Louis.
If the US was all about obeying the laws, it wouldn't exist as a Republic today, since its founders were treasonous criminals who by the laws of the empire ought to have been hanged. Why didn't blacks just obey the laws and stay at the back of the bus?
Sometimes the law is wrong. Rounding up kids into caged camps is wrong.
Of course it does, but the hypocrisy keeps the people coming. The US construction, agriculture and hospitality industries depend on Latin labour. Meanwhile, US demand for drugs and historic US interference keep their home countries in the craphouse.
The USA could easily stop people from crossing the border if they truly wanted to. You don't necessarily need a wall, you've got the most powerful military the world has ever seen. Secure your borders. And while you're being honest, cancel the US signature on the UN refugee convention, the US is no refuge.
In respect of combating economic migration, the answer is and has been simple for a very long time, if the U.S. mandated that all employers could only hire an employee with a verified Social Security Number, and the penalty for not doing so was seizure of the business, that would wipe out 95% of all opportunity for illegal immigrants.
In respect of those fleeing mass violence, primarily from El Salvador, Honduras and Guatemala its a bit more complex. The problems there are in many respect the products of past U.S. policies, but also local corruption.
Solutions at this point are hard to come by, the effort should be made. Foreign military occupation, not something to be done frivalously, and that usually doesn't work out well, should be avoided.
Be that as it may, the situation on the ground is very complex, violent and intransigent and unlivable for many.
In the absence of solving those issues in one way or another, the appropriate thing is for the U.S. to come up with a proper legal mechanism for claiming asylum, one in which this level of detention; and separation of families is not considered, let alone required.
Technically, the U.S. will say that if you arrive at a legal port of entry, from the aforementioned countries and apply for asylum, you will not go through this; clearly very few, if any, believe they will receive a fair hearing if they follow the legal route; and believe there is opportunity if they don't. Both issues, along w/the underlying ones in the origination countries requires attention.
One logical step would be to set-up pre-clearance centres for asylum seekers at US embassies in the affected countries.
File your application there.
If you do so, persuade staff there of imminent risk, and agree to certain restrictions on travel and work, then this could be handled in an orderly manner, without undue cruelty, while upholding legitimate border security.