If you look closely at the first chapter, the ending of the book is not so random, and even almost implied Anna states that "See, unlike the rest of the free world, I didn't get here by accident. And if your parents have you for a reason, then that reason better exist. Because once it's gone, so are you." The fridge brilliance comes in when you get to the end of the book. Anna wins the case, and doesn't have to donate her kidney to Kate. But her entire reason for existing was to basically be a bag of spare parts for Kate. So when she won the case, her reason for existing was gone, and so was she. It seems like a simple, meaningless throwaway line at first, but is actually very important and telling.
In the book, after winning her lawsuit, Anna tells Campbell shortly before her death that she plans to give a kidney to Kate anyway. It seems like a Shoot the Shaggy Dog, but there's actually a kind of symmetry to it: Kate was willing to make the ultimate sacrifice so that Anna could have a chance to have a life, and Anna in turn decides (now that it's her decision) to make a sacrifice of her own to give Kate a chance to have a life. Of course, the real Shoot the Shaggy Dog is that none of this ends up mattering in the end anyway.
In Greek mythology, the princess Andromeda becomes a sacrifice to angry gods. In this novel, the character Andromeda (Anna) is born to be a sacrifice, albeit in little pieces, to her sister.
Why is someone with uncontrolled epilepsy allowed to drive?
People with epilepsy are allowed to drive if they're declared fit by a doctor and are seizure free for at least a year.
This is true, but Campbell's epilepsy is pretty clearly not under control given that he has a major seizure over the course of the book and that he uses a seizure dog (it's unlikely he'd keep a service dog around just in case he has a seizure when that hasn't happened for years). The author probably just didn't think it that far through.
Why is a child whose sole reason to exist is spare bits for her dying sister not taken away by CPS?
Because the family are clearly at least upper middle class (lawyer mother, fireman father) and not the kind CPS usually checks on - unless they're given a call. And the way it's framed is Anna willingly donating small things for Kate, which she seemed content to keep doing until the possibility of a kidney transplant was on the table. For example, donating bone marrow is a safe enough procedure that won't affect the donor. It's perfectly legal, provided there are no adults who can donate to the patient. The ethical issue is of course whether children can consent, as it has to be legally approved by the parents. Strictly speaking it's considered okay as long as the benefits to the patient outweigh the risks to the donor. The child's decisions are taken into account, and for the most part Anna is a willing donor. It's not until the kidney transplant is proposed that she now has second thoughts.
And for what it's worth, Anna wasn't created solely to be 'spare bits'. The only planned donation was an umbilical cord one, which the doctors hoped would work. It didn't, so the decision to get Anna to donate was made later. So the issue was very complicated.