This is vast oversimplification of what caused the Mexican American war. Mexico never really had control over what was called “northern Mexico” except for some parts of the California coast. The borders between Mexico and the Louisiana purchase (which had just been completed) were ambiguous at best (despite what maps in modern history books depict) Most of what existed in this vast territory was completely unknown to anyone and it was only sparsely populated by settlers from not just Spain and Mexico but also France the US and other European countries. When you sum it all up Mexico’s claim to the territory was simply a paper claim that it had inherited from Spain that it put in little effort to reinforce with a physical presence. The British and the US had the same issue later with the Oregon territory. The US made multiple attempts to purchase these territories outright from Mexico because it was clear that settlers from the US were starting to outnumber Mexicans in these area and they wanted to avoid a repeat of what happened in Texas. Oh and let’s not forget that whole fact that the territory was still mostly inhabited by and has been by native tribes that didn’t have anything to do with any of these governments.