It was because Mexico and nearby states were colonised by Spaniards who influenced their culture and their language in their colonies and they left them only after the Reconstruction period ended.
Spaniards might have had a colonisation policy similar to other European powers and made it compulsory for natives to speak Spanish.