"And it came to pass about three months after" (Genesis 38:24) — not three complete months, but rather the greater part of the first, the greater part of the last, and the middle one complete. "Behold, she is with child by harlotry" — this teaches that she was patting her belly and saying, "I am pregnant with kings! I am pregnant with redeemers!" Tamar was the daughter of Shem, as it is said, "And the daughter of any priest, if she profane herself by playing the harlot, she profaneth her father; she shall be burnt with fire" (Leviticus 21:9). And therefore Judah said, "Bring her forth, and let her be burnt."
Tamar Daughter of Shem and the Three Months of Her Hidden Pregnancy
Midrash Aggadah, Genesis 38:24
ויהי כמשלש חדשים. לא חדשים שלימים אלא רובו של ראשון ורובו של אחרון והאמצעי שלם: הנה הרה לזנונים. מלמד שהיתה מטפחת על כריסה ואומרת מלכים אני מעוברת [גואלים אני מעוברת]. תמר בתו של שם היתה, שנאמר ובת איש כהן כי תחל לזנות באש תשרף (ויקר' כא ט) ולכך אמר יהודה הוציאו ותשרף: