A Pokémon that originated in a Gen 7 game (like SM) cannot be transferred to Gen 6 (like XY).
However, discounting generational differences, the games also record the OT’s gender, and I believe which game version the Pokémon was originally caught in, as well. So if you have two games of the same version with (at least) the same OT name, OT gender, ID, SID, and (in Gen 7) TSV, then, in theory, a Pokémon caught in one game would not be recognized as an outsider Pokémon if traded to the other. It’s very possible that there are other factors that the game also checks for, though, and I have no way to test this, so this may not be a conclusive answer.