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
Hadar Zekenim: This explains why he would lie with a harlot.
Malbim: It teaches why Tamar did what she did. Much time had passed, and Shelah was not given to her. Yehudah's wife had died, and he could do Yibum; and he already was consoled after his wife, for he went to shear his sheep - 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
Refer to 38:1:1:2.
What was he doing by 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.