This is only half true. Aquinas did say an unborn baby receives a soul 40 or 80 days after conception, depending on gender. But he also said abortion is a violation of natural law and is always wrong, no matter when a soul may be infused into the developing child’s body.
The 40/80-day view is based on the writings of Aristotle, who said a child becomes human at “formation,” the point at which it first “has a human form”–that is, when it looks human. He said this was 40 days for boys and 80 days for girls. Probably this distinction was based on the point at which genitals could be observed on miscarried children. Keep in mind that fetal embryology was then a restricted science; all observations could be made only by the naked eye, the microscope being in the distant future.
Aquinas accepted the idea of formation, which he said occurs when a child receives a soul. But since abortion violates natural law whether or not the child has a soul, Aquinas taught that abortion is always gravely wrong.
Today we have better scientific tools than did Aristotle or Aquinas. We know unborn males and females look human at the same time, and we know they are human long before they look human. Modern science verifies that the unborn have a human genetic code from conception, and this is when their humanity begins.
The ancients did not know about the genetic code, of course–we had to wait for Gregor Mendel, a 19th-century monk for that–and relied on outward appearances to identify species and gender. Appearance was the best test available to them, but it was hardly reliable.
Aquinas overlooked the fact that the biblical view of the soul cannot be squared with Aristotle’s. In Psalm 51:5 David says he was a sinner from conception, but sinfulness is a spiritual quality, so David must have had a spirit, a soul, from conception.