The key thing is representational memory. If you want to discriminate pain from hunger, from vision, or from any other sensational experience, you need to be able to label it in some way, and that will come from interactions with the primary caregiver.
This is an unwarranted piece of legislation because there is good evidence that the fetus cannot feel pain at any stage of gestation.
It does introduce risks to the mother if we start to inject drugs to the fetus and increase the time of the procedure. That would be unnecessary and involve unnecessary costs and risks.
From about 26 weeks you can talk about there being a complete system in terms of biology, a link from the skin to the spinal cord to the brain, and we know that set-up is reasonably functional.
I don't think the question of pain resolves the argument about abortion.