Mexico in the 1840's was a new country whose legitimacy, and hold on lands it claimed in the north was tenuous and not entirely legitimate. The United States cleverly took advantage of that situation.
The had their independence from Spain for over 20 year and had moved from a constitutional republic to a autocratic dictatorship under the military rule. The vast majorities of the "Hispanic" people of those sparsely populated territories that became part of the the United States welcomed the Americans. They had little or no loyalty to Mexico.
Even with that, the excuses for the congressional declaration of war were shaky, at best. Congress and the "administration" took advantage of an opportunity. Saying that, a legitimate reason would have likely occurred before long.