No it’s not okay. The child may feel uncomfortable with that person or maybe they’re reserved and don’t like personal displays of affection.
My step-mother used to always make us hug her brother and to sit on his knee. As a child he made me feel icky. I didn’t know why. Later, my older sister said she had been forced to sit on his knee and he had an erection. She was old enough to recognise what was happening.
So, if kids say they don’t want to hug someone, I would never, ever force them. Perhaps their experience is not mine and perhaps their instincts are at play.