In Chapter 690 of the manga, Law is facing off against Vergo, while at the same time talking to Doflamingo. When Vergo shows off his full body Armament Haki, Doflamingo states to Law that "Even your severing powers can do nothing to the strength of his Haki!"
This strongly implies that Armament Haki is able to offer some level of resistance against the effects of certain Devil Fruit powers, Law's being one of them. It is reasonable to assume that Doflamingo's proficiency with Haki is better than Law's, therefore he had increased resistance against Law's powers, such as the soul-switching ability.