I think a lot of it might be down to workplace culture and the relationships people have with one another. Also, the circumstances may make a difference. One of my co-workers gave me a hug when she learned I'd just lost my dog to cancer. I appreciated the gesture, but we were alone, and have known one another for a long time. It might not have felt as natural in a different situation or if a different person had done it.
My own rule, generally, is not to touch or hug if there's a marked difference in power between two people or if there is any doubt at all that the gesture would be welcomed. To know the latter requires more than a superficial acquaintance with someone. Also, if the person stiffens or draws away, I'd stop. Having said this, I've never been a super huggy person, and I prefer for them to be short and sweet as a rule. This got me in a lot of trouble in my family of origin, where kids were expected to submit to long, rib-popping hugs by relatives and close family friends upon greeting.
I wouldn't really be comfortable in a workplace where people were running around hugging one another constantly, but I've never run across that sort of workplace culture either. I think that in a smaller, more intimate workplace, where people regard one anther as a sort of family, casual hugs might feel more natural than in a larger one where relationships are less defined.
Of course, a big reason why workplace hugging and touching are regarded with suspicion these days is because they've been used for a long time as a form of social dominance or sexual harassment. When called out, the excuse given is "X is just being friendly" or "that's just how they are with everyone." Most of us know the difference between a creepy hug and one intended to give comfort or show friendship, I think, but it's almost impossible to have an impartial and fair rule or policy that encompasses the difference in an objective way.
Note that cultures do differ in what kinds of touching are normalized. In US corporate culture, the handshake seems to be the universal greeting, though it's not generally used to show affection, sympathy or emotional support (I have seen people gently take or squeeze another person's hand in sympathy, though).