It's likely that civil enforcement of an NDA to recover damages for answering a judge's question in a judicial proceeding would be barred by a court as against public policy, even if the NDA didn't contain an explicit provision allowing disclosure in a judicial proceeding. The theory would be that public policy prevents enforceability of contractual terms that require someone obstruct justice or to disobey court orders.
"In McKenzie v. Lynch, 133 N.W. 490 (Mich. 1911), a husband settled a civil claim with a man who had engaged in "criminal conversation" with his wife. As part of the settlement, the husband promised not to "do anything whereby this matter will acquire any publicity whatever." Id. The court found this provision unenforceable because it could prevent the husband from "becom[ing] a complaining witness, in a criminal proceeding" against the other party to the contract. Id. at 491."
(Alan E. Garfield, "Promises of Silence: Contract Law and Freedom of Speech," Cornell L. Rev. 83, 261.)
That is to say that under these circumstances, one party could not sue the other for breaching a non-disclosure agreement by testifying as a witness in a criminal trial. I'm sure there's more recent and more relevant legal authority out there somewhere.