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?