Was the United States justified in going to war with Mexico?
It is highly unlikely that the U.S. was justified; and more likely that the U.S. provoked an unnecessary dispute with Mexico that devolved into war.
Manifest Destiny was a prevailing issue in U.S. history at the time of the war, in fact James K. Polk had based his presidential campaign on America's manifest destiny to overspread the continent. At the time, Americans had moved to California and Texas in large numbers. Texas had recently fought its own war of independence from Mexico and secured its freedom under the treaty of San Jacinto which set the Mexican-Texas border at the Neuces River. Later, when the U.S. annexed Texas as a state, the border was set at the Rio Grande. An additional complication occurred when Mexico claimed the Treaty of San Jacinto was invalid as it had been signed by Santa Anna under duress. Also, President Polk offered to buy California from Mexico, a proposal which did not appeal to Mexico.
Mexico was angered by the U.S. annexation of Texas and broke diplomatic relations. In the meantime, President Polk sent a message to General Thomas O. Larkin in Monterrey, California that he would not try to induce California to join the union, but he further stated:
if the people should desire to unite their destiny with ours, they would be received as brethren.
Polk then sent Gen. Zachary Taylor to "guard" the Rio Grande, even though its designation as the legal border of Texas was disputed. Several American troops were killed in a skirmish with Mexican troops following which Polk delivered a war message to Congress, claiming that "American blood has been shed on American soil." This, of course was a matter of some debate; in fact Abraham Lincoln, then a Whig Congressman from Illinois, introduced "spot" resolutions, asking Polk to designate the spot on American soil where American blood had been shed.
The U.S. then declared war on Mexico, which was ill prepared. By the resultant treaty of Guadalupe Hidalgo, Mexico relinquished its claims to Texas, and the U.S. gained California and parts of New Mexico and Arizona. The U.S. in turn paid Mexico $15 million and assumed all American claims against Mexico. There was no significant advantage gained by the war that could not have been obtained by peaceful means; therefore the war was hardly justified.
I do not think that there is any way to justify the US's decision to go to war with Mexico in 1846. At least, there is no way to justify it using modern standards of what is right and wrong. Using the standards of the time that the war happened, it is much more defensible.
The basic reason for the war was to get territory. Pres. Polk did give other reasons for the war, but the point truly was to take part of Mexico's territory. Today, starting a war to take territory from others is totally unacceptable and can be punished as a war crime. Back in the 1840s, however, it was much more acceptable. During that time, the idea of a country taking another country's territory simply because it had the power to do so was not unthinkable like it is now.
So, this war was completely unjustifiable under our modern standards. However, it was much more justifiable using the standards of the time in which it happened.