In animals, oxytocin reduces a natural tendency to avoid other animals, and causes pair bonding.
Oxytocin's most immediately obvious effects are to precipitate childbirth and encourage lactation. My guess would be that these were its original purposes, and that the social effect came later: if you've just given birth, or if something is chewing your nipples, fall in love with anything nearby, as this will generally include the baby.
Oxytocin is also released during penetrative sex: if you're having sex, fall in love with anything nearby, as this will generally include your partner.
Something of an evolutionary blunt instrument.
Hugging also seems to release oxytocin.
Regarding autism: Given autistic social deficits, an obvious hypothesis is that there's something wrong with the oxytocin system.
Given my previous speculation, my guess would be that this is some secondary effect rather than a root cause of autism. eg perhaps autistic people are chronically stressed, and this inhibits oxytocin in some way. Or perhaps I am quite wrong, the oxytocin system is the root cause, and oxytocin release reduces stress to normal levels in normal people. Or perhaps there is a feedback loop at work.
A final thought: autistic people, being more object-centric than person-centric, may bond to objects and places in a similar way to normal people bonding to other people. Temple Grandin, for example, describes this effect.
See also Temple Grandin's squeeze machine. It's a kind of mechanical hugging device.