Both states are part of the land Mexico had to cede to the United States after the Mexican-American War (1846-1848).
See related questions for further detail.
California and New Mexico
The acquisition of New Mexico and California is called the Mexican Cession of 1848. The Mexican Cession also included California, Nevada, and Utah.
The Texas cession, which included present day California, Arizona, Utah, Nevada and New Mexico.
Present-day California, Utah, Arizona, and parts of Wyoming, Colorado, and New Mexico was included in the Mexican Cession.
Present-day California, Utah, Arizona, and parts of Wyoming, Colorado, and New Mexico was included in the Mexican Cession.
From Mexican Cession, we got present-day California, Utah, Arizona, and parts of Wyoming, Colorado, and New Mexico.
Mexico cession
California, Nevada, Arizona, Utah, Wyoming, Colorado, and New Mexico.
No - there was no slavery in the new territories - California or New Mexico or Utah. Texas was a slave state already.
California, Nevada, Arizona, Utah, Wyoming, Colorado, and New Mexico.
The Texas cession, which included present day California, Arizona, Utah, Nevada and New Mexico.
The Texas cession, which included present day California, Arizona, Utah, Nevada and New Mexico.