וַיְהִ֗י עֵ֚ר בְּכ֣וֹר יְהוּדָ֔ה רַ֖ע בְּעֵינֵ֣י יְהוָ֑ה וַיְמִתֵ֖הוּ יְהוָֽה׃
猶大的長子珥在永恆者眼中為惡,永恆者就使他死了。
Rashi
רע בעיני ה' WAS WICKED IN THE EYES OF THE LORD — like the wickedness of Onan, and committing the same sin. This must have been the case because of Onan it is said, (v. 10) “And the Lord slew him also — Onan’s death was for a similar reason as Er’s death. Why did Er commit this sin? So that she should not bear children and her beauty thereby become impaired (Yevamot 34b).
Ramban
AND ER, JUDAH’s FIRSTBORN, WAS WICKED IN THE SIGHT OF THE ETERNAL. Scripture does not specify the nature of his wickedness as it did in the case of his brother.148Verse 9 here. Instead, it simply states that he died for his own sin. It informs us that this was not by way of punishment of Judah for his role in the sale of Joseph, since the saving of Joseph’s life by Judah compensated for his role in the sale. There was no case of death of a child in the house of the patriarchs except this one who was wicked in the sight of the Eternal, since the race of the righteous is blessed. This is why Jacob mourned many days for his son Joseph, and he refused to comfort himself,149Above, 37:34-35. for he considered this to be a great punishment to himself, quite apart from his love for him.
Radak
'רע בעיני ה, the addition of the words “in the eyes of G’d,” is needed, seeing that no one else was aware of Er’s sin, something committed in the privacy of the bedroom. Our sages in Yevamot 34 said that the reason why Er ejaculated outside his wife’s vagina was in order for her to retain her beauty and not become pregnant.