In theory...
Because [18 U.S. Code § 798][1] requires a "willful" disclosure of classified information, the answer lies in the definition of the legal term 'willful'. This is not the same as being willing or compelled.
The term "willfully" means no more than that the forbidden act was done deliberately and with knowledge, and does not require proof of evil intent. McClanahan v. United States, 230 F.2d 919, 924 (5th Cir. 1955), cert. denied, 352 U.S. 824 (1956); McBride v. United States, 225 F.2d 249, 255 (5th Cir. 1955), cert. denied, 350 U.S. 934 (1956). An act is done "willfully" if done voluntarily and intentionally and with the specific intent to do something the law forbids. There is no requirement that the government show evil intent on the part of a defendant in order to prove that the act was done "willfully." See generally United States v. Gregg, 612 F.2d 43, 50-51 (2d Cir. 1979); American Surety Company v. Sullivan, 7 F.2d 605, 606 (2d Cir. 1925)(Hand, J.); United States v. Peltz, 433 F.2d 48, 54-55 (2d Cir. 1970),cert. denied, 401 U.S. 955 (1971) (involving 15 U.S.C. § 32(a). See also 1 E. Devitt, C. Blackmar, M. Wolff & K. O'Malley, Federal Jury Practice and Instructions, § 17.05 (1992).
Taken from - https://www.justice.gov/archives/jm/criminal-resource-manual-910-knowingly-and-willfully#:~:text=An%20act%20is%20done%20%22willfully,See%20generally%20United%20States%20v.
So it stands to reason that if the witness knew the information was 'classified' and they answered the question, I think they would be in some trouble.
I believe the witness can simply say something to the effect of "I am unable to legally answer that under 18 U.S. Code § 798". I would love to see a court attempt to compel the witness to answer after that statement, as it could qualify as "solicitation to commit a crime" by the court. The legal debate there would be interesting.
But don't quote me.
[1]: https://www.law.cornell.edu/uscode/text/18/798