If you switch schools you have to sit out a year of Varsity, but you can still play if you are a junior or younger. If you move far away, out of your district there is no penalty.
In the CIF Southern Section there is a freshmen transfer rule in place. You are allowed to transfer schools once at the end of your freshmen year, without moving and for any reason, and still play varsity the next year. After your freshmen year, you have to actually have a change of residence in order to play varsity. The only other exception, is a hardship waiver, but you have a better chance at winning the lottery than getting one of those approved by CIF.