The only people in a courtroom who are in a position to know what might be in the best interests of a child are his parents. And even they often disagree. Judges are required by statute to base their decisions on the best interests of the children whose lives are in their hands. But the legal system puts so many obstacles in the way of judges that it is really only by chance that they ever stumble on a ruling that is actually best for a child.
The fundamental problem for children and their parents is that the legal systems in the United States are adversarial. Conflict is largely all we know. When you walk into the courtroom, the bailiff hands each parent a hammer, and when the judge says, "Let's hear your evidence," what he really means is, start swinging. We start with the assumption that the winner of this fight will be the party who deserves to win. That much may be strictly true, in the same sense in which might does, in fact, make right. But the point is that deserving to win in the legal system often means only that you're better than the other party at story-telling and self-promotion and battering the other parent. It does not mean that you have won "on the merits," as lawyers and judges often say. And it certainly does not mean that a child is better off as a result of your winning.
These are real problems, but they are not hopeless. They are caused primarily by legislatures who make laws that judges and lawyers must live by. These laws more or less guarantee that a child's interests will be obscured by the legal system that implements the laws. So one solution is to work to change these laws.
Another solution is in the hands of parents. Know in advance that if you fight in court over your children they will suffer as a result. Know that if you put their fate in the hands of lawyers and judges, they will be injured by the legal process. And know that you do not have to submit to this process. Find a way to settle your own differences so that you can both parent your children. They need both of you. Accept that the other parent is not like you and parents differently from you. Accept that you might have to pick up the slack when you think the other parent is not doing enough for the children. And above all else, find a way to stay out of court.