Surgery doesn't change gender, gender is a social construct changed by social transition.
For the record, race is also a social construct, racist de facto caste systems are determined by skin color but they have no scientific basis.
Gender affirming surgery is in no way required for transition but is done for the mental well-being, quality of life, and in some cases ease of social acceptance of the individual.