Let’s say I invent a cure for AIDS. I then share that knowledge with a country we don’t like, such as Iraq. Could I be charged with treason for spreading medical knowledge? Or does that only apply to defense knowledge?
It probably depends on the type of knowledge that you’re spreading. If it’s something you invented yourself, I suspect that there’s no law against it. If you stole secrets from a government lab about a highly-infectious disease, and then sold those secrets to bin Laden, then yes, I suspect you’d be charged with treason.
Let’s distinguish a couple of different terms here. Treason is “giving aid and comfort to an enemy.” This would only apply to a country that we were at war with. If you sent funds to aid the army of a country that we were at war with or joined their army, you would be committing treason. Sending them medical information that you know would help them in warface might constitute treason.
A different act is giving away official secrets. To do this, you would have to know that something is an official secret. If you were doing ordinary medical research and presented a paper at a conference that a representative of a foreign country that we were at war with also happened to be attending, you wouldn’t ordinarily be responsible if this person happened to learn something that might be useful in a war. If you knew a classified medical fact and revealed to anyone not cleared to know that fact (regardless of where they were from) or if you deliberately helped someone else reveal that fact, you would be guilty of a crime.
There’s also a crime which consists of helping a terrorist organization (which, since they aren’t a nation, might be missed by the definition of treason) by providing aid to them when you know that this will enable their terrorism.