I think its referring to Genesis 38:9-10 where Judah's first born son Er, whose life is taken by God because of evilness. So Onan who was Er's brother was told to make offspring for his brother. Onan did not and wasted his seed on the ground. God was displeased and took his life also.
I think that God was displeased because of Onan's opposition to God's plans, not because he wasted his seed on the ground.