Sex is without purpose
procreation is the purpose of sex
I prefer not to word it that way since nature and evolution have no purpose.
In humans, sex results in procreation less than 1% of the time.
Practically everything in nature exists because it's been better at existing than what doesn't exist.
Sex exists because recombination of parental genes are generally advantageous to offspring.
Sex also promotes social bonding in many animals (eg bonobos).
Bonding sex in humans can keep parents together so they will more likely stay teamed up to raise offspring.
When the opposite sex is not present (eg jails and segregated boarding schools) homosexual relations can keep the plumbing and emotions primed for future heterosexual relations.
In some animals homosexuality maintains pecking order (eg spotted hyenas), improving the social stability of a group. Gay sex can work this way for humans. There is a sexually maintained pecking order in the gay community and gay communities include bisexual (reproductive) members.
Homosexuality may also be another misfiring of our clunkyly evolved brains, but since the rate is pretty stable, there's reason to believe it's occurrence is generally advantageous. We are messily evolved, but in a free society, messes are permitted.
It's easy to see advantages to certain rates and types of homosexuality, but not, strictly speaking, a natural "purpose."