Jesus did not command the demons to go into the pigs. Rather, the demons requested it, and Jesus simply allowed it. It makes no difference to demons whether they inhabit people or pigs because they can make people into pigs by getting them to trade their God-given natures for animal behavior.
In light of the current epidemic of teen suicide, I find it more than coincidental that the demons caused the pigs to prefer suicide to life.