JohnD said:
The text suggest that Onan practiced coitus interruptus
That would be the logical interpretation. Since he was being forced to impregnate his sister-in-law, he wouldn't have been allowed to do anything less.
I have always understood (but with no evidence) that the idea contraception should be sinful was thought up by people who found the idea of sex so repugnant that it could only be justified by the necessity of propagating the human race
That makes a lot of sense. There are those who cannot grasp the concept that sex can actually be free and - at a simple level at least - fairly easy. This old saying - which my grandmother knew well - says a lot:
"You've had the sweets so now you must suffer the sours."
By sours of course she meant children. Far from being a 'gift from God' children were a penance!

If you start from that position it automatically follows that contraception is a bad thing.
I propose the following explanation for this nonsense which someone on a TV discussion programme started but somehow failed to finish.
It is widely believed that, in our not-so-distant evolutionary past, our proto-human ancestors lived in groups but didn't form pairs. Now the mating rules for such a society are simple; one or two dominant males lay claim to all the females. That's how chimps do it today. The exact process by which we evolved into a pair forming species and, moreover, the only one that uses sex for pair bonding is not obvious but it is very clear that some aspects of our proto-human past still haunt us.
When was the last time you heard a politician, or anyone else with the public ear, say that sex is a good thing? Probably never. How often do you still come across the implication that 'good' women don't like sex?

This insidious lie has blighted the lives of generations of women and hasn't done most men any favours either. The only beneficiaries have been the small number of men who made the rules but kept a pool of 'bad' women aside for their own use.

A chimp would see that as perfectly normal!