Sometimes it’s okay to say no to a treat. Friendliness and kindness can only go so far until they are unwanted.
Just as a parent wouldn’t allow their child to eat candy from a stranger, so the same logic applies here; dogs shouldn’t eat treats from strangers, especially if their parent disapproves.
The main reason behind resisting a stranger’s treat is the fact that it could be harmful to the dog. The gesture is most likely innocent, but no one can be certain of the condition of the treat and whether it is safe to eat. The dog could have an allergic reaction to the treat, or even worse; there could be a stranger out there seeking to hurt dogs who intentionally gives out harmful treats.
One type of stranger to watch out for and possibly not be is the stranger who is so willing and prepared to offer a treat, this will raise suspicion. To strangers who love giving dogs treats and to dog parents who love taking their dogs out and don’t mind meeting new people: The best way to meet in the middle is for the parent to bring treats along with them. If anyone wants to give the dog a treat, the parent is aware of what their dog is eating, the exchange is safer, the dog gets a nice treat and the stranger has their little interaction.