They can't really prohibit anyone from writing the code, but only from publishing it, but what would happen then if exactly as you say go to a country where it is allowed and publish it there? Even if you return, on what legal grounds are they going to sue you? It's is going to be almost impossible for them to forbid writing code.
Of course, the government cannot stop developers to write the code, no way to stop it. But since they prohibit publish it, it is very annoying for developers, they must move to another country. Actually, the government must understand that prohibition isn't the right solution, should consider other proper ways. Why don't think about making some regulations but not stop it, right? The regulation should be friendly with the developers and fulfill what the government wants.
Maybe they don't even have to move to another country. What if they set up a company with a partner in a country where it is allowed to publish the code or make a deal beforehand with someone who publishes the code in their own name in a country that does not prohibit people from publishing the code? I think there are a lot of ways around it if that turns out to be a problem. I don't see a realistic way for government to crack down on people who write code and hand it over to someone who is allowed to publish. There is a similar problem with ghostwriting. If a ghostwriter writes a thesis and argues that he didn't know it was for academic purposes or abuse, there is nothing you can do against the ghostwriter unless the court can prove otherwise, and they can't if there isn't somewhere a written note that states exactly what the court needs.