Basically, if you're going to work for money in a state, you have to comply with that state's laws. Some states have a law that says if you earn money in their state (some forms of employment are exempted), you have to pay income on a share of your annual income, with the share being proportionate to the amount of time you spent working in the state. So if you spend one week working in the state, then you pay state income tax on 1/52 of your annual income.
When it comes to sales, such as your house sale, the law says that sales are considered to have taken place wherever the exchange was completed. If your sale was in CA, then you have to pay CA sales tax regardless of where you reside.