If the purpose of changing a male into a female is to perform a surgical operation to cut the penis and testicles and create two openings, one for the urethra and the other for sex, and to give the person doses of female hormones that affect his appearance in the appearance of a female in the emergence of the breasts and the absence of beard hair and so on, and the purpose of changing the female to male for her to have an artificial penis implanted and doses of male hormones given to make her look like men, with no protruding breasts, beards, and so on; all of this has no effect, and the female does not turn into a male nor does the male turn into a female with any of that, in addition to what the aforementioned operations require of looking at and touching the private parts without a legitimate justification.
But if what is meant is the transformation of a male into a female and vice versa, according to the internal and external reproductive systems that are the basis for distinguishing one sex from the other, then this is something that does not object to it in itself, regardless of its premises and forbidden comparisons, but it appears that it has not been achieved until our time, which is the matter that is being achieved. Usually the first.
Yes, some surgeries may be performed for someone who has a deformity in his reproductive system, such as delusion that he is a female because his penis and testicles do not appear, so it turns out after the medical examination that he does not have the internal female system, but rather has a penis and testicles that are retracted – for example – so the doctor performs a surgical operation to show them or has a resemblance The penis and testicles, so he is under the illusion that he is male, and after a medical examination it is found that he possesses the female reproductive system from the ovary and uterus, so the doctor cuts off the excess flesh and removes what looks like a penis – for example – and this is not objectionable in itself and this is not a change of a male to a female or vice versa.
(S. Sistani's website)