Sonic's transformation into the Werehog in Sonic Unleashed is all thanks to Dr. Eggman's scheme.
Eggman built a machine that trapped Sonic. If Sonic tried to use his Super Sonic power, the machine would drain away the Chaos Emeralds and force him back to the ground. Somehow in the process, Sonic ends up transformed into the Werehog.
As for exactly why, there are a couple of theories. One is that the electrocution from the machine triggers the change. Another, more precise explanation is that Sonic's Chaos Emerald power is taken from him and replaced with Dark Gaia's energy, which is what turns him into the Werehog.