How to be a co-author anonymously?
You are clearly in a tricky situation that the usual customs of academic publishing are ill-prepared to deal with. There definitely doesn't seem to be a standard, off-the-shelf solution to your problem like some kind of registry for anonymous authors. However, with a bit of creativity there might be a path forward. I suggest the following:


Agree to collaborate with the researcher from country C, but make clear to him/her that you would like your identity to be kept secret for an indefinite period. Make sure that the collaborator is okay with mentioning you as an anonymous coauthor not just in the paper you end up publishing but also in talks, presentations, posters etc. Make sure this is a person reliable enough to trust on such a serious matter, and keep in mind that as with any secret, there is always an unavoidable risk that the truth will come out and somehow make itself known to officials in your country.
If/when you write a paper on the project, have the collaborator submit it to a journal, asking the journal to list you as an anonymous coauthor, under a name such as "John Doe", with a note explaining that this author chooses to remain anonymous due to fear of political persecution. I cannot be sure, but this strikes me as a request that a reasonable journal is likely to agree to. The journal may ask to have your identity disclosed to them so that they can at least have it on record for legal reasons. It may be okay to reveal your identity to them (which could actually help later on in your career when you wish to get the credit for the work), but keep in mind that this again increases the risk that the secret will come out before you intended it to or will become known to the wrong people.
If/when you ever wish to claim credit for the work in connection with job applications or other career-related reasons, make sure you have a reliable promise from your collaborator to vouch that you are indeed the coauthor, as well as some supporting evidence like email records, files, notes, etc. E.g., you and the collaborator can plan to have him/her send a letter of recommendation explaining the situation if and when you need it. Or, you can have the collaborator publicly disclose your authorship, e.g. in a signed letter he/she will send to you that you can post on your website. If the journal knows your identity you can ask for similar confirmations of your authorship from the journal.

Keep in mind that it may be good to have a backup plan in case something goes wrong, e.g., the collaborator dies or turns out to be unreliable, or is worried about political repercussions for him/herself in country C. Having supporting evidence as I mentioned above, and having a few other people you trust know about your authorship, will all make it easier for you to confirm your authorship if and when you want to. Of course, the more people know your secret, again the higher the risk that the truth will come out in an unintended way.


The thing to remember in this analysis is that there is no approach that is entirely without risk. Given that political persecution is no joking matter, you would be well-advised to give very serious thought to the risk you are taking versus the possible reward. I don't know which countries you're referring to in the question, but I can think of examples where if your actions became known you could easily be accused of espionage and thrown in jail for many years.