I've been around toddlers with small animals. I don't care if he didn't intend the dog harm, he was likely causing the dog harm. Toddlers tend to put their full force of strength into a hug, and wave the animal back and forth violently, neither of which is conducive to "not harming" said animal. The brat was likely crushing that poor dog, and the dog reacted accordingly.
Yep, "Nice Pet!" and "No Touch!" were among the first things we taught the nephew, even before he started walking.
For a one-year-old, he's pretty good with the animals: he knows he has to sit first (keeps him from chasing them, falling on smaller pets, or being knocked over by the bigger dogs), can't pull hair/ears/tails, can only pet gently, and can't chase them when they leave. We're still working on getting him to keep his face away from them, for a variety of reasons. If he tries any of that, we take him away from the area. Teaching him all that took a
lot of effort on our part, and at that age he still has to be monitored and have what he's learned reinforced. We're not allowing him to hug the pets for now, for reasons you've already pointed out.