That’s a good example, but most contracts have language such as “if any clause of this contract is found to be invalid, the rest remains in force”.
So yea, in a case like that that part of the contract would be struck, but it isn’t a get out of jail free card for the entire contract.