Why did Yehudah and Bas Shu'a give their sons such derogatory names ('Er' - childless, and 'Onan' - mourner)?
Targum Yonasan: Because Er would indeed die without children and Onan would cause his father to mourn for him. 1
Ramban: Yehudah actually called his son 'Er' meaning to arouse, 2 and Bas Shu'a 3 called her second son 'Onan,' because she had a difficult birth. 4
Hadar Zekenim, citing a Midrash: Er's name should have been 'Ra,' 5 only he 6 reversed it to 'Er.'
Pesikta Zutresa (2): Due to the sale of Yosef, Yehudah was stricken through his wife and children. Their names hint to the sale. Er - [Yosef] was Hu'arah (emptied) from the world. Onan - He brought Aninus (mourning, to his father) over him. Shelah - (Yehudah) erred. 7 He was in Keziv - He lied [about the sale].
Malbim: Bas Shu'a had not converted before they were born, and therefore her sons' end was bad.
And Chazal say that when parents name their children, they are inspired by a spark of Ru'ach ha'Kodesh.
Ramban: As in "Orerah Es Gevurasecha" (Tehilim 80:3).
Ramban, Hadar Zekenim (to 38:4): It was customary for the father to name the first son, and the mother, the second.
Ramban: As was common in those days. See 35:18, and Divrei Hayamim I 4:9.
Oznayim la'Torah: It suddenly struck Yehudah that he was going from one bad situation to another - (a) He advised the brothers to sell Yosef; (b) He was removed from his position of leadership (and lost his money); (c) He moved away from his brothers and his father's house, and (d) He married a Kena'anis and had a son from her.
Presumably, this means that Hashem gave Yehudah Ru'ach ha'Kodesh to call him 'Er.' (PF) Refer to 38:3:1:1*.
The Targum of "Shegagah" is 'Shalusa.'