The enforceability of pre-existing contracts is typically based on the law at the time of execution. Subsequent changes in law may not invalidate contract terms that were legal when made, unless retroactive effect is explicitly stated or public policy is strongly implicated in favor of retroactivity.
For example: A lease agreement requiring a tenant to pay all property taxes could still be valid after a law change that would normally prohibit such clauses, provided the lease was signed before the change and no specific retroactive application affects it.