There is an obvious difference between losing an skirmish to having literally every knowledge about your opponent, having multiple chances to fight him and beat him, and even then miserably losing at the end.
-Sanji didn't lost against Vergo, he got hurt in a clash, he still put up prior and post that, then they had to leave the area to do other stuff.
-Sanji lost against Doflamingo due to a hax who could get the best out of everyone back in the day, as it actually did. Still, its a loss, but not a veredict of complete inferiority at every scenario you can try to picture of them fighting.
Oda made us sure that Law didn't had a chance to beat Doflamingo, he made Doflamingo look at Law and say "Bro, look at you, you're doing your best but you simply can't beat me, give up! (while being missed an arm)"
With Sanji he simply made Doflamingo call him a strong guy, despite getting the best out of him in their first clash ever very early in the arc. With Luffy, he simply kept fighting Mingo until they were evenly matched at some point, despite Luffy not doing well many other times before that.
There is honestly no comparison between these.
And as i said before, Sanji beat Queen, he didn't fought 2 top tiers like they were Tobiroppos, and proceeded to beat one of them and achieve a 3 Bi bounty post getting shat on by Doflamingo in all the possible ways lol