From https://www.mlb.com/glossary/transactions/postseason-roster-rules-eligibility:
A player who doesn't meet said criteria for postseason eligibility can still be added to a team's roster in the postseason via petition to the Commissioner's Office if the player was in the organization on Aug. 31 and is replacing someone who is on the injured list and has served the minimum amount of time required for activation.
I read it as 1) He was in the organization on Aug 31, 2) the corresponding move to add him to the 40 was moving Mejia to the IL, 3) cleared with the Commissioner's Office, which is probably just there as a safeguard in case something is totally sketchy.