Actually, Zalgo possessed Tails/Miles's body thanks to Eggman.
While making a deal, Zalgo tricked Eggman that "Sonic will be forever defeated and fallen to his world, if he will let him to possess any mobiled-enough vessel."
As the events of the game are representing bad ending (A.K.A Sonic did not collect any Chaos Emeralds, leading to losing his sidekick to Eggman's hands), Eggman decided to let Zalgo possess Tails's body, hoping that he will actually defeat Sonic and will take him to his world.
Of course, all of this was just a plan of the global trickery.
Zalgo took over the island, and it was Sonic's detiny to start fixing all the mess Eggman has caused.