Not all contracts are legally binding. The stereotypical law-school example is: you cannot sell yourself into slavery. At least not in the US. Pore over your local laws and you will find phrases like "such-and-such is contrary to public policy" meaning that contracts involving such-and-such will not be upheld.
But there are two entirely different questions here. One is unilaterally cancelling your contract. The other is money. There are situations where you can be made to pay for a service you didn't receive, but they're pretty narrowly constrained.