There is no direct Biblical teaching against Onanism per se, only that Onan was killed by God for withholding his semen to make an heir for his dead brother. Onan was a son of Judah. From Judah’s line, an heir would come; the one that would bear the Messiah. That the spiritual Dynamics were such God would take such a direct hand, as noted by the writer, Moses, should cause the biblical student to take pause. However, as an event from which formal teachings against contraception and masturbation are derived, that seems a stretch beyond what is already in the Mosaic levitical texts.
Is this passage of scripture the source of the Catholic Church’s teaching against contraception?
So this was not a distinctive Catholic "thing". All of Christendom --- Protestant, Catholic, and Orthodox --- had understood for 2 millennia what was going on in Genesis 38, and had understood that God had instituted procreation as one of the goods of marriage, and hated what Onan had done to reject and sabotage His fruitful design for sexuality.
I don't think God would allow the entire Christian community and all its various sub-communities to be misled about this for 2 millennia, only to vouchsafe His real, holy, contraceptive intentions to the Anglicans, of all people.
[Sorry,Anglicans, I love ya but I had to say that.]
To answer your second question: the Catholic Church bases her teaching on Divine and Natural Law. Divine Law tells us from Genesis to Revelation that marital union was designed to be both unitive and fruitful, that it is a good when it is, and a bitter misfortune when it is not. There is not a single instance in the OT where births are not identified as blessings, and where sterility is not identified as a sign of people rejecting God, or God chastising His people.
Natural Law tells us that it is ethical to use drugs, devices and surgery to restore and strengthen natural physiological function, and unethical to intentionally impair or injure normal, natural function.
IOW, it's not virtuous to sabotage the healthy body. We are not the masters of the source of life. We are the ministers of God's design.
Do you believe that human sexuality embodies God's design?
"Is this passage of scripture the source of the Catholic Churchs teaching against contraception?"
It's the most explicit and therefore easiest to refer to Scripture, so a qualified "yes" is probably the best answer. There are other reasoned arguments but in the age of soundbites and short attention spans they've fallen by the wayside. Most people no longer care enough about their immortal souls to honestly work through a well reasoned argument as opposed to a quick, one line, answer even if the answer is based on something taken out of context.
But you just need to actually let "Scripture interpret Scripture" in good "Sola Scriptura" tradition to arrive at the same conclusion.
Deuteronomy states the penalty for refusing to continue your brothers line and it is definitely not the death penalty. Therefore when Scripture says God killed Odin because of what he did it means just that, not for his intention to not continue his brother's line. So what was it he did as opposed to what he intended? What he did was he spilled his seed on the ground and for what he did God struck him down.
The fact that the contraception supporting crowd who argue over the meaning of Odin being struck dead ignore their own espoused method of interpretation in order to not interfere with their preferred interpretation has long been a source of entertainment for me.
It something of an acid test, actually, of who actually studies Scripture to arrive at the correct interpretation as opposed to saying they have a Scripture based belief when in fact they have just adopted the first lame interpretation that suits their preferences.