That’s literally true as written, but there is more to it than that, one that I think even a lot of tax preparers overlook. The definition of custodial parent only matters to determine when the rule for divorced and separated parents in IRC § 152(e) applies. The tax regulations provide the definitions of custody, custodial parent, and noncustodial parent as follows:
Originally Posted by LdiJ
(c) Custody. A child is in the custody of one or both parents for more than one-half of the calendar year if one or both parents have the right under state law to physical custody of the child for more than one-half of the calendar year.
(d) Custodial parent—(1) In general. The custodial parent is the parent with whom the child resides for the greater number of nights during the calendar year, and the noncustodial parent is the parent who is not the custodial parent. A child is treated as residing with neither parent if the child is emancipated under state law.
Treas. Reg. § 1.152-4(c) and (d). (Underlining added). Note that in subsection (c) the regulation defines custody as having the right under state law to physical custody of the child. Under state law, however, the parents lose the right to physical custody of their children once they reach the age of majority. The kid at that point has the legal right to determine where he lives and is no longer under the physical control of his parents. The first sentence of subsection (d) does indeed state the rule you did. But then the second sentence, which I underlined, emphasizes what the definition of custody makes clear: that once the kid is emancipated no parent is considered to be the custodial parent and thus for the purposes of the divorced and separated parent rule the child is treated as not having lived with either one of them. (I left out the remaining part of subsection (d) that discusses how to determine the nights spent with each parent as that is not relevant to this discussion.)
So what does that mean for determining who may claim the child (if anyone) as a dependent once the child is an adult, i.e. age 18 or older in Pennsylvania? If the kid was an adult for the entire year it means that you have to look at the qualifying child test and qualifying relative test without the benefit of the rule for divorced and separated parents.
For the qualifying child test, this means that the adult child must be both under age 24 and a full-time student and that the adult child must reside with the parent claiming him for the entire year. Just living with the parent for over half the year is not good enough. And, of course, the child must not have provided over half his own support.
If no one is eligible to claim the child under the qualifying child test then we have to look to the qualifying relative test. Under the qualifying relative test it does not matter with which parent the child lived or how old the child is, or whether the child is a student. But only the parent who provided over one-half the child’s total support may claim the child. And if the child had more than $4,050 in gross income (for 2017) no one may claim him under the qualifying relative test.
Finally, how does the rule for divorced and separated parents fit in when the child became emancipated (turned 18) during that tax year? IRS Publication 501, page 14, explains that by way of two examples:
Example 5—child emancipated in May.
When your son turned age 18 in May 2017, he became emancipated under the law of the state where he lives. As a result, he isn't considered in the custody of his parents for more than half of the year. The special rule for children of divorced or separated parents doesn't apply.
Example 6—child emancipated in August.
Your daughter lives with you from January 1, 2017, until May 31, 2017, and lives with her other parent, your ex-spouse, from June 1, 2017, through the end of the year. She turns 18 and is emancipated under state law on August 1, 2017. Because she is treated as not living with either parent beginning on August 1, she is treated as living with you the greater number of nights in 2017. You are the custodial parent.
Publication 17 for 2017 is available on the IRS web site here: https://www.irs.gov/pub/irs-pdf/p501.pdf