Human don't have sex only for purpose of procreation. Sex for primates has huge role in bonding and relieving stress as well.
Bonding is a lesser function.
The primary, fundamental function of sex was obviously reproduction.
And that still underlies a lot of human behaviour; including opportunistic cheating while in pair bonded/supposedly monogamous couples.
A lot of opportunistic sneaky cheating on men's behalf's is thought to be seed spreading/gene spreading. Producing as many offspring as possible; even with women he doesn't pair off with or support ... There's a chance the offspring will survive.
On female behalf's opportunistic sneaky cheating is thought to be to; vary their offspring's genes (and the gene pool) and - very commonly - to produce offspring with perceived alpha males (including dark triad males) who are not single or available or who won't commit to & pair bond with them (but will have sex with them) while maintaining the support & resources of non alpha, non dark triad etc. males who will commit.
They are even proven to choose different types when ovulating, compared to not ovulating.
It is - almost entirely - about reproduction, even if we've thrown a giant spanner in the works with contraception in recent times (obviously a tiny fraction of time compared to human evolution).