The church's prohibition on contraception is based
essentially on Onan in Genesis.

If God did not want man to 'spill his seed' why did
God design males such that they have nocturnal
emissions?

Granted, it is not a deliberate act by men.
However, the nocturnal ejaculation is the result of
brain activity focused on producing pleasure, not
children. This bodily function starts well before
the age of marriage.

God did that. God designed the male brain and
anatomy so that there would be ejaculation outside
of intercourse in marriage. Why? Why did God do
that?

Answer by Judie Brown on 9/29/2017:

Karen

As Father Steven Torraco has pointed out, the nocturnal emissions of the male happens
naturally and is not in any way to be confused with sinful actions such as the use of
contraception or masturbation or others types of sexual sins.

Father Brian Harrison, a noted theologian, explains the sexual sin of Onan in a way that I think
will help you see why your question is divorced from logic because there is a huge difference
between what God has designed for man and the sexual sins committed by man. Harrison
writes

"...when sexuality is treated in its most sublime character -- i.e., marriage as a sacred
mystery symbolizing God's covenantal love with His people -- the Bible's allusions to the
conjugal act are predominantly indirect and allegorical. The implications of this for Genesis
38:9, wherein Onan's sexual act is described in starkly explicit terms, are clear.

"It should be remembered also that we are here dealing here with a culture which so
abhorred that other form of "wasting the seed" -- the homosexual act -- that it prescribed
the death penalty for this offence. In the light of this and the other factors we have
considered, I submit that it would be not only exegetically unwarranted, but quite
anachronistic, to suggest that the Genesis author, in line with the 'political correctness' of
late twentieth-century Western liberalism, would have taken a relaxed, indulgent view of
Onan's method of preventing conception -- his "spill[ing] the seed on the ground." We should
note also the parallel between the description of homosexual acts as a "wicked" or or
"abominable" thing in the Leviticus texts and the similar qualification of what Onan did in
Genesis 38:10."

The complete article is at https://www.catholicculture.org/culture/library/view.cfm?
recnum=2940