Why does the Torah find it necessary to inform us that Bas-Shu'a died?
Seforno: Now it was proper for Yehudah to take in his daughter-in-law into his house, to replace his wife. 1 It is because he didn't, that she despaired of performing Yibum, and did what she did.
Hadar Zekenim: Because it explains why he would be intimate with a harlot.
Malbim: To justify what Tamar did. Much time had passed, and Shelah was not given to her. Yehudah's wife had died, and he could perform Yibum; and he already was consoled after his wife's death - seeing as he went to shear his sheep, and they used to make a feast and Simchah at the time.
Seforno: In the same way as Avraham brought a wife for Yitzchak to marry, to bring into Sarah's tent after she died.
Why did Yehudah's wife and children die?
Sotah 13b: Such is the fate of someone who starts performing a Mitzvah but does not finish it. 1
Hadar Zekenim (to 38:1): Due to his involvement in the sale of Yosef, and in his father's pain. Refer to 38:1:1:2 .
Why did Yehudah go to his sheep-shearers?
Targum Yonasan: The sheep-shearing season had arrived, and he went to shear the sheep.
Ramban #1: He went there every day to comfort himself on the loss of his wife, by putting his mind on the sheep.
Ramban #2: Yehudah was a celebrity, and at the sheep-shearing ceremony, many people, including the poor, would gather for a large Se'udah. 1
See Shmuel II 13:23.
Over what was Yehudah consoled?
Ha'amek Davar: He had been pained over the loss of his sons and his wife. Really, it was not so long (after Onan died), just it felt very long, because he was pained that he has no way to increase his seed (refer to 38:6:151:1). Now that his wife died, he could remarry, so he was consoled also about his sons.