The Mexican War (and the issue of Texas which helped cause it) was very closely connected to the fight within the United States over slavery.
The two are connected because the Mexican War brought huge areas of new land into the United States. This land was going to have to be either free or slave. This would, potentially, upset the balance between free states and slave states.
The fact that the war would be disruptive can be seen in debates over it. For example, the Wilmot Proviso stipulated that all land that might be taken from Mexico would have to be free. This caused huge amounts of conflict between slave and free states. After the war was over, the newly taken land led to such things as the arguments over the Compromise of 1850.
When the United States went to war against Mexico in 1846, philosopher Ralph Waldo Emerson famously said that "Mexico will poison us." He meant, in short, that slaveholding states coveted the lands possessed by Mexico, and that their acquisition through war would led to toxic political disagreements within the United States. This was true from the time Texas gained independence from Mexico (after fighting a war caused by, in part, the fact that slavery was outlawed in Mexico). Debate over whether to annex Texas was controversial because first, annexation would likely lead to war with Mexico, and second, because its admission would give the slaveholding states more political clout. When annexation (favored by the slave states) did finally come, it indeed led to the Mexican War. This war was also supported heavily by the slaveholding south, and many in the North saw it as the result of a conspiracy by the "slave power" to dominate the Union. This belief was reflected in the controversial Wilmot Proviso, which proposed to close the territories gained through the war to slavery. When the Mexican War was over, debate over slavery was accelerated by the application of California for admission to the Union. This led to several issues, including the status (free or slave) of the territories acquired by Mexico, which culminated in the doomed Compromise of 1850. So the admission of Texas contributed to the outbreak of the Mexican War, and the issue of slavery was what made each of these events politically toxic.