The terms 'first' and 'second' world originally arose in the context of the Cold War. The First World was NATO and allies (mostly those who made up the Western Allies in WWII), the second world was Warsaw Pact dominated by the USSR, and the third world was the rest - mostly members of the Non-Aligned Movement. In that sense Mexico could probably be categorised as 'non-aligned', they have observer status in the Non-Aligned Movement, and as such could be called third world. However, they did support communist nations - most notably Castro's Cuba as well as Venezuela. Why they did this is complex, but it is often attributed to a desire to display independence from the foreign policy of the USA.
If by first world you mean in the colloquial sense of 'poor countrty' in which it's come to be used, then that's a more complicated question. The more technical distinction is between developing and developed nations, although that's been criticised lately. Mexico isn't poor by global standards, it's a member of the OECD and isn't ranked as a developing nation by the IMF. Compared to Canada and the USA it is poorer, but I suspect the poverty is exaggerated in the American popular consciousness.
/u/NewZealandLawStudent's answer is excellent. By way of addition: The United States took roughly half of Mexico's territory for a mere $15 million as a result of the war of 1846-7. In 1848 in a portion of that territory huge deposits of gold were found (the famous Sutter's Mill/Northern California Gold Rush of 1848-9). By the end of 1851 something like $220 million (in 1851 dollars) had been taken out of these gold claims. Further, California contains some of the richest farmland in the world, and has long supplied a large percentage of the United States' agricultural yield. That doesn't even get into the silver deposits of Nevada and Colorado, the uranium in New Mexico, or any number of mineral and agricultural benefits of that territory that have accrued to the U.S. instead of Mexico.
Further, the war of 1846-7 heavily destabilized the Mexican government, which had only been independent of Spain a short while and was already reeling from the loss of Texas the previous decade. The instability and loss of money caused by the war enabled the continual re-emergence of Antonio Lopez de Santa Anna, who took advantage of this instability on several occasions to re-assert personal rule over the country, forestalling the development of a more robust civil government.