At the outset, I don't understand why people are voting to close this question. The question presents an interesting issue of contract law.
Can a Rental Contract Supersede State Law?
No, not in your situation. The doctrine of contra proferentem is decisive, and it favors your position unless you are the party who drafted the lease contract (which is unlikely in a landlord-tenant context).
The clause establishing a six-month statute of limitations is in conflict with the tenant's right (per the same contract) "to pursue legal action within 30 days of terminating the lease". That is, the contract creates an ambiguity.
Because the 30-day deadline has not expired --by virtue of your lease not having been terminated yet--, the doctrine of contra proferentem dictates the ambiguity is decided or solved by adopting the option that favors the party who is not the draftsman of the ambiguous contract.
There is one note of caution, though. You mention that the statute of limitations in CA is four years, and also that the habitability issues lasted four years. At first glance, the latter suggests that the CA statute of limitations might have expired anyway (depending on the exact dates when your claims --specifically, your losses-- accrued). If that's the case, you need to be careful about what legal theory (or theories) to pursue. Some of these theories could be to proceed on the basis of:
- Breach of contract by establishing that your losses accrued at the instant(s) the landlord failed to fix the issues;
- Unjust enrichment accruing at the instant when the landlord refused to reimburse you for rent overpaid (assuming that reimbursement is consistent with the language of the lease); and/or
- Fraud, if you are able to prove that the landlord intentionally misled you, and that your reasonable reliance on his representation(s) caused you losses.
Note that although in California "there is not a standalone cause of action for 'unjust enrichment,' which is synonymous with 'restitution', [...] [unjust enrichment and restitution] describe the theory underlying a claim that a defendant has been unjustly conferred a benefit through mistake, fraud, coercion, or request. [...] The return of that benefit is the remedy typically sought in a quasi-contract cause of action.", Astiana v. Hain Celestial Group, Inc., 783 F.2d 753, 762 (2015).
(For further information on the prima facie elements of these claims under California law, search for these terms at leagle.com)
The decision on which theories to pursue depend on additional, specific facts and details which are not reflected in your inquiry.