There is no hard and fast rule. This varies from case to case, location to location, judge to judge. Remember that this is only one factor in the decision that the courts make and their consideration is the "best interest of the child." That may or may not be what the child himself wants.
As a general rule, think in terms of 7s. A 7 year old can testify in court as a fact witness because at that age they generally know the difference between truth and lies, can understand the importance of telling the truth in court, and can understand the consequences of not telling the truth; but they are too young to handle the emotional decision of who they want to live with in a divorce situation. On the other hand, a 14 year old can generally be trusted to have enough maturity to express a preference for living with one parent over the other and can articulate the reasons why which can have a bearing on the decision made by the court. The judge alone decides how much weight to give that preference.
CAVEAT: I have a law degree, but I am not practicing, and this is not legal advice, only general information on how the law looks at this issue.