I agree with Mojavpa to a certain extent. I think that hugs have developed into something more sexual than they originally were. But i'm pretty sure that, like Mojapva said, they originated from the need to be comforted or to feel safe, the same way that baby monkeys cling to their mothers bellies.