Both male and female same-sex sexual activity are illegal in Iran and punishable by death (Islamic Penal Code of Iran, 1991).
A formal book of fatwas by Ali Khamenei, the Supreme Leader of Iran, states that it is permissible in Islamic law to have sexual reassignment surgery to determine the true sex of a person. According to the Constitution of the Islamic Republic of Iran, judges are to rely on such fatwas (interpretation of Islamic law by an Islamic scholar) in making decisions in the absence of codified law.
Gender Identity Recognition
The Constitution of Islamic Republic of Iran, 1979: The Constitution creates formal legal authority for fatwas by authorities of Islamic law.
The judge is bound to endeavor to judge each case on the basis of the codified law. In case of the absence of any such law, he has to deliver his judgment on the basis of authoritative Islamic sources and authentic fatwa. He, on the pretext of the silence of or deficiency of law in the matter, or its brevity or contradictory nature, cannot refrain from admitting and examining cases and delivering his judgment.
Replies to Inquiries about the Practical Laws of Islam (Grand Ayatollah Sayyid Ali Hosseni Khamenei, 1997): This fatwa establishes that Islamic law permits sexual reassignment surgery.
Q1271. Some people have the appearance of men. They have female psychological and sexual tendencies though. If they do not undergo the operation of sex change, they might commit sins insofar as their sexual behavior is concerned. Is it permissible for them to undergo such an operation?
A: There is no harm in undergoing the said operation if the end result would be determining of the true sex of the person provided that it does not lead to the commission of any haram act or a consequent vile deed.
link to the text in PDF: Iran-SOGI Legislation Country Report-2013-eng