Ah in that situation, your trouble would be with the Iranian government when you travel back to Iran? Of course countries can generally pass laws that do anything (they can execute people no?). In western legal tradition extra territoriality is reserved for special situations. In places like Iran where the rule of law is weak it does not apply.
But then in that sense Iran can do whatever it wants once they get their hands on you, laws or not