So we like sugar whenever we can get it - and suffer dental caries and diabetes. We lust, because our ancestors' lust helped pass their lustful genes on to us. But sometimes the convention breaks down. If we are on the Pill, or know that our sexual partner is, it doesn't diminish our desire. We still inherit the ancient rule of thumb, now out of date.
Genetic effects are often conditional.
Genes have an 'IF Statement' in their programming. IF you find yourself in a male body build a penis, otherwise build a clitoris. In species like seals and deer, where males hold large harems, it is easier for a male than for a female to become a wildly successful reproducer, but easier for a female to become a reproducer at all. Harem-holding males pass a disproportionate share of genes on to the future, which leaves other males passing none. Females are mostly harem members and their reproductive success is middling, between the male extremes.