I'm not a lawyer, but severability clauses are generally a thing when needed, both in contracts and in laws. As I understand it, courts are also reluctant to strike down an entire law or contract if the entire thing is not what is being challenged. Answering a question of law outside the bounds of the question the parties are asking the Court to answer is called an "advisory opinion," and illegal in many jurisdictions.
IAMNAL but there’s usually a clause to say that if some part of the agreement isn’t valid/can’t be enforced/etc then the rest of the agreement stands regardless. Who knows how well that stands up though (probably lawyers somewhere, but I doubt it is cited often).
Its one of those weird peculiarities present in US law which apply virtually nowhere else but show up in quite a few agreements across the world.
I wonder how valid the whole agreement is if it contains points which one can not possibly agree to.