So let's say an army officer is caught by the enemies and wants to spill the beans. The patriot officer can either lie and mislead the enemy and get killed or can betray the country by telling all the secrets of the state. So according to Buddhist principles which is worse? Lies or betrayal? Can you lie for a greater cause? If one's intentions are for the greater good can it still be bad karma?
I Buddhism what matters is the roots (greed, hatred, delusion, non greed, non hatred, non delusion).
Greed, hatred and delusion are unskillful as they give results which you would perceive unfavorably hence resulting in a unpleasant sensation in the future. They are unskillful as they reap an undesired result and is not connected with the goal in Buddhism which is to be free from unsatisfactoriness which is to transent the sphere of perception and sensation (sanna vedayita nirodha).
Non greed, non hatred, non delusion are skillful as they reap experiences which you perceive favorably in the future.
So it depends on the root or volition behind the action. The same action can be done with different motivation which decide whether it is skillful or not.
As of my understanding if he did any wrong, it will come to him as bad Karma. And Good will come as good Karma. Lets say the officer here lied and protected his country. He will be punished for lies and will be blessed with the good work of protecting the country.
Can anyone lie with a not lying intention? I think we can't. If we want to lie. Then we are lying and we know we are lying. Purposes may be good. But the real intention can't be good (In here, lying is wrong, but the purpose of lying is good).
This is how I understand.
The officer could just do nothing or better yet the officer could send loving-kindness and compassion to the "enemy". Loving the enemy well is a good tool to get out of that situation.
Both lies and betrayal are wrong because they will lead to suffering in the future if not right away according to the Buddha's teaching (Buddhism).