Ayatollah Khomeini issued a fatwa to that effect, which was then given effect in the Islamic Republic of Iran, so in the Islamic Republic of Iran, it's flexible enough to allow for sex changes, and it encourages sex changes. But if you want to change your religion in Iran, you've got some serious problems. There are other problems. You're allowed to change sex, but if you want to be a homosexual, theoretically at least, you face the death penalty. Quite how often these penalties are carried out is a moot point, but it's there on the statute books.