The answer by Dale M is correct that a contract cannot require you to violate the law, or prevent you from complying with a legal obligation.
But it is also true that a contract which violates a public policy can be held to be void, or read as if an exception to permit compliance with public policy were included implicitly. It is generally public policy that people should cooperate with a law enforcement investigation, and a contract that purports to prohibit such compliance may be void, even if no subpoena is issued.
Note also that the terms of any civil settlement, including any confidentially agreement, must be agreed to by both (or all) parties. Party A could insist that the agreement make an exception for responding to inquiries by law enforcement, even without a subpoena.
The exact wording of the confidentially agreement may well matter. The question describes the hypothetical agreement as providing that:
you cannot disclose the nature of the settlement, or disparage party "B".
That would not, as written, prevent you from accurately and objectively describing to law enforcement the actual events which led to the settlement, without giving the actual terms of the settlement. If B's actions are described factually, B is not being "disparaged", particularly if it is in a confidential statement to law enforcement.
If such a case arose in real life, party A would be wise to consult a lawyer to learn what s/he can say, and under what circumstances, before having substantive discussions with the police. A might wish to have counsel present during any interview with the police. If A's lawyer advises that A should only disclose certain facts in response to subpoena, A can inform the police that there are facts that s/he will only disclose in response to a subpoena. The police might well then obtain one.