In Genesis chapter thirty-eight, verse eight, Onan, Judah’s second son, is to go with Er’s wife Tamar and have a child with her for his brother’s sake. Judah tells Onan to take Er’s widow Tamar as his wife. Onan has to care for Tamar as a wife, with a distinct emphasis on providing her with children, so his departed brother would have some offspring by proxy. While the practice seems strange today, it was a strong custom in the region. The tradition intended to keep a man’s family line from being “cut off,” if possible, and served the interests of the widow, who would be left destitute and helpless without children to support her later in life.
Onan unexpectedly was in a position to perform this “levirate marriage.” According to the law, Er’s brother, next in line, did not have many options but to fulfill his obligation. Still, Onan did take Tamar as his wife, including intercourse but deliberately avoided providing her with children. Instead, Onan takes sexual advantage of Tamar and later dies shortly after. Judah’s second son did not fully agree with the fulfillment of the law, only part of it.
Today, apart from the law in those days, many Onans do not mind the sexual advantage of the marriage thing. However, the responsibility after with the children and everything, some step up to the challenge. Some men want the intercourse fling but not the responsibility that comes after that is attached to that thing. That is why God slew Onan because he was irresponsible. This example shows that God did not make sexual intercourse a plaything where men and women go around changing partners having a “fling-thing” to abort marriage and the wedding rings. God instituted marriage to avoid living that immoral way of life and eliminate that corruptive manner.