Reason 1: You probably got the one from trading.
Reason 2: Probably some kind of sort of a glitch with duplicating legendaries, not sure though.
Reason 3: Some sort of a hack...? I have no clue what this is, but you probably activated some sort of cheat that allowed two wild Terrakion to appear, but not sure.
You should check the OT of both of them.