It is the most complex mystery I have encountered in evolution. I'll quote from Bateman & Bennett. 2006. The biology of human sexuality: evolution, ecology, and physiology.
The female orgasm, with no ejaculation, is more difficult to explain. Female orgasm is not limited to Homo sapiens; certainly, chimpanzees experience it. The most parsimonious explanation for female orgasm is that, just as the clitoris is a homologue of the penile glans, so is the female orgasm a homologue of the necessary male orgasm: in other words it is merely an epiphenomenon, a side effect of parallel development of males and females. In support of this view, it is pointed out how rarely the female orgasm occurs from intercourse (a third of women in a British study reported never, or rarely, having an orgasm during intercourse). Another view is that, regardless of the male and female orgasm originally being ‘mere’ homologues, there can still be selection for satisfying, pleasurable female orgasms if they help to ensure a strong pair bond between sexual partners. In the pygmy chimpanzee, or bonobo (Pan paniscus), females will rub their clitorises together to climax. The bonobo clitoris is much larger than that of humans, and orgasms in this species do seem to act as social bonding device.
Physiologically, it has been suggested that the orgasm may have a very clear adaptive function in that it stimulates the mouth of the cervix to dip into an ejaculate deposited in the vagina, aiding uptake and hence likelihood of fertilisation. Against this argument is that for this to happen the female orgasm has to occur after the male orgasm (unless the cervical movements continue after the orgasm) and most women (Western, Caucasian) report that their orgasms usually occur before that of their partner.
Depressingly, the primatologist Sarah Blaffer Hrdy (1999) has pointed out that, even, if orgasms do function to “dispel tension and strengthen bonds between partners”, for the vast majority of women in much of the world, living in aggressively patriarchal societies, orgasms, reflecting libido and sexual assertiveness are more likely to get a woman punished, beaten or killed. Many societies have customs such as veiling, purdah, and, worst of all, genital mutilation through clitoridectomy (total or partial excision of the clitoris) and infibulation (sewing together of the vaginal lips). If there is any kind of selection in action here, Hrdy suggests that the female orgasm may once have been an adaptation, but now is no longer selected for, and will disappear.