Two grounds for taxing, and they can both apply to the same dollar. A state may tax a resident on all of their income, wherever it was earned. A state may also tax a nonresident on income sourced within it, most commonly wages for work physically performed there, income from a business operating there, and rent or gain from real property located there. Someone who lives in one state and works in another therefore has two states with a legitimate claim on the same wages. This is the ordinary case rather than an edge case, and the system's answer to it is a credit rather than an exemption.
The resident credit, and the constitutional floor under it. A resident state generally allows a credit for income tax paid to another state on income that both states tax. In Comptroller of the Treasury of Maryland v. Wynne (2015) the Supreme Court held that Maryland's personal income tax scheme violated the dormant Commerce Clause because it did not give residents a full credit for income taxes paid to other states. The Court observed that, unlike most other states, Maryland did not offer such a full credit, and applied the internal consistency test to conclude that the scheme operated like a tariff on interstate activity. The practical reading is narrow but useful: a resident credit is not merely a courtesy that a state may withdraw at will. What the credit does not do is equalise rates. It is generally capped at the home state's own tax on that income, so a resident of a lower-tax state who works in a higher-tax one ends up paying the higher of the two.
Residency is a test, not a fact, and there is more than one of them. States distinguish domicile, which is the place a person treats as their permanent home and which changes only when a new one is established, from statutory residency, which some states apply to anyone maintaining a place of abode in the state and spending more than a threshold number of days there. Because the two tests are independent, a person can satisfy one state's domicile test and another state's statutory residency test in the same year and be a resident of both. The detail of those tests, and of the day-count records that decide them, belongs to the state tax residency page.
Federal law caps what a state may reach in one important case. 4 U.S.C. 114, headed "Limitation on State income taxation of certain pension income," provides that "No State may impose an income tax on any retirement income of an individual who is not a resident or domiciliary of such State." The definition of retirement income is broad, covering distributions from qualified plans, simplified employee pensions, 403(a) and 403(b) arrangements, individual retirement plans, section 457 deferred compensation plans, governmental plans, military retired or retainer pay, and payments made as substantially equal periodic distributions over life expectancy or a period of at least ten years. This settles a widespread and expensive belief. A state where a pension was earned cannot tax the payments once the recipient has genuinely moved away, which is a matter of federal law rather than of that state's generosity.
The federal deduction is a separate subject. Paying state income tax may produce a federal itemized deduction, subject to a cap, and that deduction is governed entirely by federal law. It belongs to the SALT deduction page and has no bearing on what any state charges. Local income taxes charged by some cities, counties and school districts run on their own authority again.