I think there are a few reasons. I believe we need a certain amount of touch. Too little and we start to have problems, too much and we begin to feel like we don’t own our own bodies. @tranquilsea pointed out that babies do not thrive when they do not receive enough touch. As they grow into children they are more likely to be found rocking back and forth, trying to comfort themselves. When they take vitals of people, it can be observed that our blood pressure and heart rate go down when we are being touched, or even when we touch. This is part of the reason pets are brought into nursing homes, not only because the elderly might miss having their own pet, and enjoy watching the dogs, but because being able to pet them is relaxing and good for their health. They might have very little touch otherwise. Anyway, hugs are accepted culturally as platonic (usually) and ok for friends.
Moreover, we have routines in bonding that make us feel safe and comforted. When we are young our moms, and other adults in our lives hold us while they bond with us. It can be while we are feeding as babies, or when we rest on our parents lap and they stroke our hair so we fall asleep. Or a hug. The routine and the association of these things to being with someone who cares about us, signals that touch is related to love and safety.
All these things, both psychological and physiological, are why I think the hug feels good, as long it given by someone we want the hug from.
I did mention that I think there is such a thing as too much touch. Think about when you have a baby and a three year old, and they are basically on top of you all day. One breast feeding, the other needing your attention, trying to carress the baby while half on top of you while you hold the infant, and more. Then your husband wants to come home and touch you?! Aren’t you touched out? Don’t you want your body to have a break? Maybe you can muster up willingness to have sex, but do you want a whole bunch of forepay?
As far as sex goes, I think most adults get their touch this way. I don’t think we realize it, but I think it is one of the driving forces.
Lastly, I think there are cultural influences also. My husband cannot get used to hugging someone as a greeting, unless they are close family. He especially doesn’t get hugging without kissing (on the cheek). In the midwest it is very common to hug when you have not seen each other in a while. While in other parts of the country a kiss hello is more common. kiss is more common for gay people, Latin Americans, Europeans, and others. I don’t think my Latin American friends would quickly give a hug during a difficult time to a friend, not as fast as the average American. I could be wrong.