Some written laws are by their nature merely default rules, others are binding in both common law and civil law countries.
For example, many countries (both common law and civil law) have a law that says something like, "someone who is not paid as agreed pursuant to a contract is entitled to statutory interest on the unpaid amount at 8% per annum, compounded annually, in the absence of an agreement to the contrary."
A ToS provision that said that any amounts payable for a breach of the ToS accrued interest at a rate of 12% per annum, compounded monthly would differ from the written law, but could override it because the law itself is merely a default provision.
On the other hand, suppose that a country has an usury law (again something common in both civil law and common law countries) that says that any provision providing for interest rates in excess of 6% are void and that in such cases no interest of any kind can be collected. In that case, a ToS providing for an interest rate of 12% per annum, compounded monthly would be void as against public policy and would not overrule the written law.
In general, a ToS that purports to override a binding non-waiveable law are void and unenforceable as a matter of public policy and provide do not provide a defense to someone who breaks the law, at least with respect to that term, and with respect to the entire agreement if that term is not severable (e.g. if it goes to the core of the agreement).
Betwixt that general analysis is the question of choice of law. Carrying on our example, charging interest generally, would be void as against the mandatory public policies of the laws of Iran, since Islamic law prohibits the charging of interest, but would be legal under the laws of Colorado in the United States.
As a general rule, a contract between two parties can specify which jurisdiction's laws apply to the contract in a choice of law provision, so long as that provision has a reasonable relationship to the parties and their agreement. So, if one party to the contract was based in Colorado, a ToS providing that Colorado law applies to the ToS would ordinarily be valid.
If the issues related to the ToS were litigated in Iceland or Utah despite local usury laws that prohibited contractual consumer interest rates in excess of 6%, the choice of law provision in the ToS would probably not itself be held to violate public policy and the ToS would probably be upheld.
But, if the issues were litigated in Iran, the court would probably hold that the choice of law provision itself violates the public policy of Iran and would probably refuse to enforce it, because the prohibition on interest in Islamic law would be considered much more fundamental (similar to the violation of the U.S. Constitution in the U.S.) than a violation of a mere arbitrary line-drawing statute from another jurisdiction.