It's not legal if the demotion was due to the surgery or the medical condition which required the surgery; such would be a violation of the law (e.g. the Americans with Disabilities Act) which bars employment discrimination on the basis of "disabilities." If you think this was the case, contact the state's equal/civil rights agency or the federal EEOC.If the demotion can be shown to be due to an unreleated reason, such as poor performance at work, giving your former job to someone with demonstrably better experience or credentials, or a change in enrollment so that they did not need you in the former job, then it would be legal. The key is, it can't be related to the medical condition or surgery in order to be legal.