Three documents are key to understanding how Mexico was able to achieve independence from Spain. These same documents attempt to join the fractured society under the most inclusive umbrella possible. Mexican society featured groups that often held interests that were in opposition to the goals of the other groups, or to the cause of the nation. There was little consensus on what form of government was desirable. While independence was achieved, it initially resulted because loyalists realized that Spain could no-longer maintain control over the colony and that they would have to face the masses of creole, castes, and Indians alone. It would be left for the new government of Mexico (whatever form that would take) to deal with the nation’s many deep divisions. At the moment of independence, The Mexican Empire was declared a constitutional monarchy. Mexico’s challenges were extensive. Understanding Mexico’s actions in 1846 are only possible in the context of 1821.
The first two links are very quick reads.
The Plan of Iguala, 1821
An attempt to reconcile the traditionalist and liberal elements of Mexican society toward the cause of independence. Often referred to as The Plan of Three Guarantees, the plan is the product of negotiations between Agustin de Iturbide (loyalist military leader) and Vicente Guerrero (rebel leader). It contains three primary ideas: The Roman Catholic Church would be independent Mexico’s only religion, the Mexican Empire would be constitutional monarchy, and there be racial equality.
https://faculty.chass.ncsu.edu/slatta/hi216/documents/iguala.htm

Flag of The Army of Three Guarantees sourced from: https://en.wikipedia.org/wiki/Army_of_the_Three_Guarantees
The Treaty of Córdoba
As Iturbide’s victory was becoming more apparent, the new Spanish Captain- General Juan O’Donojú entered into negotiations with Iturbide. The negotiations resulted in The Treaty of Córdoba, which recognized the independence of the Mexican Empire.
The September 28, 1821 Declaration of Independence
Mexico’s Provisional Government issued The Declaration of Independence of The Mexican Empire on September 28th.
https://s3-eu-west-1.amazonaws.com/s3-euw1-ap-pe-ws4-cws-documents.ri-prod/9780415842785/primary%20documents%20ch%206.pdf
This is a link to a great blog article describing these documents and their importance to the development of independent Mexico. It is a bit of a longer read than the first two articles.
https://searchinginhistory.blogspot.com/2015/06/plan-of-iguala-plan-towards-independence.html