6 And Judah took a wife for Er his firstborn, whose name was Tamar.
7 And Er, Judah’s firstborn, was wicked in the sight of the Lord; and the Lord slew him.
8 And Judah said unto Onan, Go in unto thy brother’s wife, and marry her, and raise up seed to thy brother.
9 And Onan knew that the seed should not be his; and it came to pass, when he went in unto his brother’s wife, that he spilled it on the ground, lest that he should give seed to his brother.
10 And the thing which he did displeased the Lord: wherefore he slew him also
Things didn’t turn out very well for Judah’s first two sons. Each of them died prematurely, as a result of one wickedness or another. We do not know what Er’s crime was, but Onan’s had to do with not fulfilling his obligations under levirate law. This law stated that if a man was married, but died without children, then his brother would take his wife and have children with her. This was meant both as a respect to the prematurely deceased brother, as well as a boon to the widow, who would depend upon the care of her children in her elder years.
The details of this ritual will later be spelled out in the law given by Moses, but evidently it was already a custom many years prior. Certainly it seems a strange tradition today, one that is based on social constructs that we have long since distanced ourselves from. As such, I think it would be difficult for any of us today to fully appreciate all the feelings that would have been going through Tamar, Judah, and Onan at this time. It does that this was an intensely awkward situation for them, though, and surely it is an awkward passage for us to read through as well.
Which brings up an interesting point. The religious are often stereotyped as being stuffy and prudish, but the book that is the very bedrock of Christian and Jewish belief is an unapologetic and explicit record. The sexuality, violence, and depravity that affected these people was very real, and the book does not shy from recounting these details. Among all the other things that the Bible is, it is a very intimate look into both the best and worst of humanity.