Spain claimed Texas in 1519, although it wasn't really colonized until the early-mid 1700s. Texas revolted against New Spain in 1836 and joined the Union in 1845, triggering the Mexican War (1846-8). The treaty ending the war gave the US basically the whole SW quarter of the continental USA.
Treaty of Guadalupe Hidalgo (1848)
This treaty, signed on February 2, 1848, ended the war between the United States and Mexico. By its terms,
Mexico ceded 55 percent of its territory, including the present-day states California, Nevada, Utah, New Mexico, most of Arizona and Colorado, and parts of Oklahoma, Kansas, and Wyoming. Mexico also relinquished all claims to Texas, and recognized the Rio Grande as the southern boundary with the United States.
***
... When the Senate reluctantly ratified the treaty (by a vote of 34 to 14) on March 10, 1848,
it removed Article X guaranteeing the protection of Mexican land grants. ... {This cost many Tex-Mexican landowners their property, which was taken over by rich (read: plantation-owning) white settlers. This left many of Texas' Hispanic citizens newly impovershed, and many never recovered. This despite that many fought beside the white settlers for independence, and towns in South TX are named in honor of these war heroes. The white settlers were mostly slaveholders, after all, and they didn't see much difference between black and brown
property people.}
***
https://www.archives.gov/milestone-documents/treaty-of-guadalupe-hidalgo
Always remember that there were a lot of brown "Mexicans" living in the Southwest before the US acquired it -- they never crossed the border, legally or illegally. The border crossed them -- and whose fault is that ?
(This map does NOT include Texas, which at the time extended up into present-day Wyoming.)