Pokémon stored in a save file need to be handled by someone. If the current save file is not the OT, then it is with the save file (as a handling trainer) and is adjusted to be correct in the save file by applying handling trainer data.
Handling trainer being OT requires OT details to match the Pokémon, such as the OT Name, ID, and trainer gender.
There is a setting to disable the auto-fix, but if disabled, the Pokémon won't be legal in the save file.