Each state has different rules for establishing residency, so it would depend on what state you are talking about. However, for tax purposes, generally you will pay state taxes to any state where you earned income, regardless of where you lived when it was earned.
If this answer has been helpful, please press the "accept" button. Positive feedback is also greatly appreciated. Thanks for the question and have a great day.