Fortunately you were able to prove ownership! Too bad that they tried to steal your dog from you.
I’m surprised the officer didn’t ask the guy who approached you to call “his dog”. Since the odds are against him naming your dog by his actual name, it would be unlikely that your dog would leave your side to approach a stranger—especially a stranger whom he would perceived irritated/angered you by his demands.
Anyone tried to do that to me when I was with MY dog and they’d soon get acute lead poisoning.