(Speaking about how things are in the US. I don't know how they are elsewhere.)
Contract law is about how to interpret and adjudicate contracts when there is a dispute between the parties in the contract.
Nothing about that means that violating a contract, in and of itself, is illegal. You aren't going to suffer any criminal penalties for failing to adhere to your contractual obligations.
What you may do is suffer whatever penalties that the contract specifies will happen if the contract is violated, and the legal system is also geared to work out and enforce such things. But that's a world apart from the notion that violating a contract is "illegal".