This anonymous source claims that female virgins cannot be executed in Iran. From 'I wed Iranian girls before execution':
In a shocking and unprecedented interview, directly exposing the inhumanity of Supreme Leader Ali Khamenei's religious regime in Iran, a serving member of the paramilitary Basiji militia has told this reporter of his role in suppressing opposition street protests in recent weeks... The interview took place by telephone, and on condition of anonymity. It was arranged by a reliable source whose identity can also not be revealed...
In the Islamic Republic it is illegal to execute a young woman, regardless of her crime, if she is a virgin, he explained.
This second source claims that this practice was based off of an 'misunderstanding'. “Female prisoners who are virgins must be raped before execution, to prevent them from entering heaven.”:
Excerpts of Montazeri’s book on the rape of women in the Iranian regime’s prisons:
In December 2000, Hossein Ali-Montazeri, a 79-year-old cleric who had been for 10 years the designated successor to Khomeini, the supreme leader of the theocratic regime in Iran, published his memoirs...
In effect, he acknowledges that the rape of girls in the mullahs’ prisons was a widespread and systematic practice. He writes: “many of those who were being arrested in connection with the PMOI were girls and they were executing them on charges of waging war on God… I told the judiciary officials and Evin officials and orthers, quoting the Imam, that they must not execute girls from the PMOI. I told judges not to write death sentences for girls. This is what I said. But then perverted my words” and quoted me as saying: “Don’t execute girls. First married them for one night and then execute them.”
I doubt whether such a law actually exists or has existed. This /r/ProIran post denies the existence of this law. Here's a discussion on a Wikipedia talk page regarding this subject.