See hadith 4909
Narrated Abu Salama:
A man came to Ibn `Abbas while Abu Huraira was sitting with him and said, "Give me your verdict regarding a lady who delivered a baby forty days after the death of her husband." Ibn `Abbas said, "This indicates the end of one of the two prescribed periods." I said "For those who are pregnant, their prescribed period is until they deliver their burdens." Abu Huraira said, I agree with my cousin (Abu Salama)." Then Ibn `Abbas sent his slave, Kuraib to Um Salama to ask her (regarding this matter). She replied. "The husband of Subai'a al Aslamiya was killed while she was pregnant, and she delivered a baby forty days after his death. Then her hand was asked in marriage and Allah's Messenger (ﷺ) married her (to somebody). Abu As-Sanabil was one of those who asked for her hand in marriage".
Abu Darda' (Allah be pleased with him) related from the Prophet (ﷺ) of Allah (ﷺ) that he came upon a woman who was in the advanced stage of pregnancy at the door of a tent. He (the Holy Prophet) said: Perhaps he (the man accompanying her) intends to cohabit with her. They said: Yes. Thereupon Allah's Messenger (ﷺ) said: I have decided to curse him with such a curse as may go along with him to his grave. How can he own him (the child to be born) and that is not lawful for him, and how can he take him as a servant for that is not lawful for him?