You can get into some serious trouble. Stuff like voiding the whole contract and providing an easy way to sue. The problem is that nobody knows everything that is illegal, even lawyers and judges get tasked with determining legality and maliciousness. Heck, try to get the complete list of federal regulations.
It often is illegal to make a contract to do something illegal.
However, the contracts are usually written to say that any parts which are found to be illegal are severed from the contract, so as long as such clauses are allowed, very few contracts are likely to illegal.