Actually, the way it works for most states, you first pay taxes to the state where you work. You then calculate taxes on that income in the state where you live, and reduce that tax liability by the taxes paid to the state where you're working.
Here's an example I just gave to one of my clients. Let's look at a scenario of the following 3 states:
NH - no income tax
MA - 5.3% income tax
CA - 9.3% tax
If you live in NH and work in MA, you pay the 5.3% tax to Mass, and no tax to NH. If you live in MA, and work in NH, you pay no tax to NH, and then the 5.3% tax to MA. So MA gets 5.3% either way.
If you live in MA and work in CA, you pay the 9.3% tax to CA, and since that tax exceeds the 5.3% rate for MA, pay no taxes to MA. And if you live in CA but work in MA, you'll first pay the 5.3% tax to MA, and then the 9.3% tax to CA will be reduced by the taxes paid to MA, leaving a 4% tax to CA. Either way, you're paying the 9.3% tax.
Please note that some states have reciprocity agreements with their neighboring states, which means that you pay taxes based on your state of residency, no matter where you work. In that case, the state of residency you claim determines the rate that you'll pay state taxes.