Sometimes it's for valid reasons, but not always. The California code does address this and even states an age, apparently believing that by that age the child has enough reasoning power to make the decision; but the child's decision is subject to the court confirming it. Meaning, it may not happen.
Parental alienation is fairly common in cases, often (in attorney's experience) it's the mother doing it, but not always. Sometimes a parent with narcissistic tendencies may tend to do this, see
https://www.psychologytoday.com/conditions/narcissistic-personality-disorder for information on this problem generally. The afflicted parent will continue to push the fact that the child must stay with him/her even when lacking a factual basis. Attorney has seen many cases where the parents actually share custody but fight about everything anyway. Usually that is due to a build up of resentment in the relationship for varying reasons, and the parents never (and I mean never) resolve their own issues. Instead, they carry the resentment forward, which is not helpful.
California Family Code Section 3042 (a)-(d) states:
(a) If a child is of sufficient age and capacity to reason so as to form an intelligent preference as to custody or visitation, the court shall consider, and give due weight to, the wishes of the child in making an order granting or modifying custody or visitation
its reasons for that finding on the record.
But parents sometimes find that emotional scars to one parent will cause that parent to become the "enemy" and then the battle doesn't stop. Unless the actual facts support harm to the child, it is often the attorney that has the better common sense argument who will win out. As for the child, he/she might get lucky.