There should be an entire forum dedicated to this issue, but I hope I can clarify a few things.
For adults and those other than college students, residency is determined by your presense in a state and your desire to remain there indefinately. Generally, if you live in a state and work there, you are a resident. Under the constitution, states are required to grant the same rights to all US citizens, regardless of their state of orgin. The Supreme Court has ruled, however, that certain exceptions can be made, such as charging a different tuition for in-staters versus out-of-staters or new residents. Thus, you could be a resident of a state and not qualify for in-state tuition and also no longer qualify for in-state tuition in your old state. One interesting exception is students who are at college can still retain there state of original residence under certain circumstances.
If you examine the rules carfully, most states try to avoid a potential confusion of words by referring to "domicile" as what determines if you get in-state tuition. Rules of domicile vary from state to state and most determinations are made by the school, so if you have a close call, plead your case to the school, sometimes they go for the student in close cases.
An interesting exception to all these rules is for military personnel. You can maintain your original state of residency indefinately as long as you are on active duty -- this is pretty cool because you can stay a resident of a state with no income tax. I do not know whether spouses can do the same. The exception that I noted in my first post, however permits a non-resident military member or spouse to get in-state tuition even though not a resident. Here is New York's law:
355 h (3) of the New York State Education Law
3) Such regulations shall further provide that the payment of tuition and fees by any student in any state-operated institution of the state university who is a member or the spouse or the dependent of a member of the armed forces of the United States on full-time active duty and stationed in this state, whether or not a resident of the state, shall be paid at a rate or charge no greater than that imposed for students thereat who are residents of this state.
I hope this helps.
Ed