Evolution is a process. It can't assign a purpose to anything, because "purpose" doesn't exist outside the minds of people, similar to "justice" and "hope."

The "purpose" of sex is whatever we choose it to be.