A contract will be deemed void and unenforceable if the contract was designed to promote an unlawful purpose.
For example, you cannot enter into a contract with someone to pay them to be your getaway driver after you finish robbing a bank. These are crimes and therefore any contract that involves such unlawful purpose cannot be enforced.
Importantly, the unlawful purpose limitation is not specific to crimes, nor is it applicable only in situations where the unlawful purpose forms the core of the contractual bargain. The legal jargon may be getting a bit complicated, so let’s jump right back in to a few more examples.
Suppose that you are a food truck operator, and you enter into a contract with a venue wherein you pay the venue a monthly “rental fee” to allow you to park your food truck on the premises and sell to attendees. Unfortunately, you do not have a valid food truck license. As such, operation of your food truck without a valid license is technically illegal. Despite the fact that the license was not the core of the contractual bargain, the contract necessarily touches upon an unlawful purpose — if it were enforced, it would be promoting an unlawful purpose (e.g. operation of a food truck without a license). By necessity, the contract would therefore be rendered void and unenforceable.
Now, alternatively, suppose that you are selling a non-fiction, short-form biographical narrative to a magazine. The magazine purchased the story on the basis that it contained purportedly true, if controversial and scandalous revelations about a local businessperson. The magazine does not have its own editorial staff — it purchases fully edited stories for publishing. You enter into a contract with the magazine to purchase the story. Unfortunately, it is later revealed that the statements made in the story were false and defamatory. The contract would likely be declared void, as defamation is unlawful (though it is a civil wrong, not a criminal wrong).