I agree this is a weird area of the law. "Intention" is the thrust of how the law handles it. I'll try my best to explain:
Abortion is usually legal for
fetuses before viability is reached. (Or, afterwards if the fetus is determined incompatible with life [like having no brain or no lungs or something] and ONLY in a handful of US states.) By extension: When a fetus is aborted, there's also the assumption that the woman had no intent to raise or care for it, perhaps she has no resources (broke, teen, future single mom, druggie, etc. etc.), or she is mentally unfit to be a mother (drug user, BPD, ADHD, narcissist, etc. etc.), or she would otherwise be forced to abandon the child to the system if she actually gave birth to it (has a lot of potential unintended consequences,
see Ukraine orphanages for an extreme example).
On the other hand, it's considered double homicide when you kill a pregnant woman who is intentionally having a wanted baby, because it's assumed the baby would have been carried to term and everything. By extension: The woman intended to raise the child and take responsibility for it. (The kid would have most likely been cared for and loved if the woman gave birth)