What was the connection between the Mexican War and slavery?
It was not so much the Mexican War as the territory gained as a result of the war which ignited the slavery debate. An uneasy truce had previously existed between the Free and Slave States as a result of the Missouri Compromise. This tenuous peace was shattered when Representative David Wilmot of Pennsylvania introduced a resolution modeled after the old Northwest Ordinances, which would have prohibited slavery in any territory gained from Mexico. In supporting his resolution, Wilmot stated
God forbid that we should be the means of planting this institution upon it.
John C. Calhoun of South Carolina responded with resolutions of his own, the famous Calhoun Resolutions argued that Congress had no right to prohibit slavery in the territories as the states owned them, not the U.S. Government. Therefore the prohibition of slavery would be a violation of the Fifth Amendment which prohibited the taking of property without due process. The end result was the polarization of the slavery debate, even though neither resolution passed. Sen. Thomas Hart Benton commented that that Wilmot and Calhoun had created a pair of scissors which alone were powerless but together would cut the union in two. Sadly, his words came true as each side became so entrenched in its position that passion superseded reason.
The connection here is that the Mexican War made the issue of slavery even more important than it had been before.
In the Mexican War, the US gained a huge amount of territory from Mexico. When it did so, the issue arose as to whether this territory would allow slavery. This meant that the deal that had been made between the North and South in the Missouri Compromise no longer applied. Once this happened, the slavery issue was reopened. The North and the South quarreled bitterly over the issue from this point on and the Civil War ensued before too long.