You must have a valid immigration document for the academic period in question.
The migratory document required to study in Mexico is defined by nationality:
Non-restricted nationalities: Require an FMM (migratory form obtained upon entry to the country), and do not need a student visa if the stay is for 180 days or less (semester or summer terms).
Restricted nationalities: Require a visa that must be issued at any Mexican consulate or embassy, regardless of the time of stay. To review the list of restricted nationalities, visit: https://www.gob.mx/inm
Everyone coming to Mexico for more than 180 days (a year or more), is required to have a student visa.