Actually a contract does not require compliance with the law to be valid. And enforcement is subjective to circumstance so a judge is always the one to rule on that.
For example i could write a contract that says you agree to be my slave and work without pay perpetually.
You are correct in the sense of "I can use a pen/computer and write down/type any words that I want." You are incorrect in the sense that a legally-binding contract is not allowed to contain just anything under the sun.
A contract which involves an illegal act is a prime example of a void contract, which is one that is never binding on any party to it because it cannot be enforced as a matter of law. You are correct that it would have to go before a judge to actually be declared void, but you are incorrect that the judge has any discretion whatsoever in that case, because the law says that contracts involving illegal acts are themselves illegal. You are also completely wrong that someone has to be convicted of a crime before a lawsuit can be filed over a contract involving that crime.
If you signed and agreed to that contract then I could demand you fulfill services or threaten legal action (civil legal action) to obtain remedy. A court order could also be issued requiring compliance with the terms.
You could demand it, but you would be unable to prevail as a matter of law because slavery is illegal, and courts cannot enforce contracts for things that are illegal.
When it’s a matter of illegality (as in a prosecutable activity) then an entirely separate branch of government gets involved and also a different court system.
The criminal and civil tracks differ mostly at the trial level. The Circuit Courts of Appeal, for example, are the same for criminal and civil cases. The Minnesota Supreme Court hears both civil and criminal cases. No, an "entirely separate branch of government" is not involved for civil cases, seeing as the judicial system, which is one of the three branches of government, encompasses both civil and criminal issues.
It would only require reporting that the individual who asked you to sign said contract is engaging in slavery (which is illegal). And then they would be indicted, tried and likely convicted.
These two sentences constitute the only part of your post that is accurate. But it's also irrelevant to whether you can enforce a void contract, which you cannot.
Once the conviction occurs then you can go to court and sue to have the contract invalidated. LOL
Just…no.
A similar matter of complication has come up time and again with the US President’s liberal use of NDAs for all employees.
Just because a contract is an NDA does not change the fact that it cannot be enforced if the acts in question are illegal, which means the contract is void, at least as to the illegal acts. You cannot contract away someone's ability to report you for murder, which is what you've attempted to do to the law in your post—mutilate and murder it beyond all recognition.
Basically, your entire post is wrong.