Lying under oath in court is not allowed to JWs under the "theocratic warfare" clause. But they can refuse to answer. In the US that is allowed, not to answer--5th amendment of the Bill of Rights.
***
w54 10/1 pp. 597-598 Christians Live the Truth *** Even in court under oath circumstances arose in totalitarian countries, such as under Hitler’s rule, where the brothers were faced with two evil alternative courses. One course was to tell everything one knew and incriminate and expose brothers to persecution and punishment and also bring sentence upon oneself. The other course was to refuse to answer questions while on the witness stand and be held for contempt of court. In similar circumstances today it is up to the individual to choose whether he wants to answer or not. Refusal means punishment. He can choose to stay silent and go to prison or speak and multiply his punishment or place his brothers in danger. He has no choice on lying but he does on refusing to answer, remembering that he must pay the penalty that Caesar imposes, which may be years of imprisonment. A Christian will not lie under oath, and therefore those in Nazi Germany had to suffer the consequences of living where there was no justice, where it was a crime to be a Christian. Jehovah gave them strength and wisdom to endure it. However, this is not to say that a person should always remain silent before an unjust court. There are times when good can be accomplished to the honor of Jehovah’s name by giving a bold witness. Jesus Christ pointed out that his followers would come before the rulers to give a witness and that they would speak. (Matt. 10:17-20) Acts 22 and 26 show how Paul gave a bold, tactful testimony before the authorities. So it is left to the accused Christian to judge whether it is advisable under the circumstances to speak freely or not, but if one chooses to speak he must tell the truth.
Not to be confused with lying when no under oath
***
w60 6/1 p. 352 Questions from Readers ***As a soldier of Christ he is in theocratic warfare and he must exercise added caution when dealing with God’s foes. Thus the Scriptures show that for the purpose of protecting the interests of God’s cause, it is proper to hide the truth from God’s enemies. A Scriptural example of this is that of Rahab the harlot. She hid the Israelite spies because of her faith in their God Jehovah. This she did both by her actions and by her lips. That she had Jehovah’s approval in doing so is seen from James’ commendation of her faith.—Josh. 2:4, 5; Jas. 2:25.
This would come under the term "war strategy," as explained in The Watchtower, February 1, 1956, and is in keeping with Jesus’ counsel that when among wolves we must be as "cautious as serpents." Should circumstances require a Christian to take the witness stand and swear to tell the truth, then, if he speaks at all, he must utter the truth. When faced with the alternative of speaking and betraying his brothers or not speaking and being held in contempt of court, the mature Christian will put the welfare of his brothers ahead of his own, remembering Jesus’ words: "No one has greater love than this, that someone should surrender his [life] in behalf of his friends."—Matt. 10:16; John 15:13.
More info
***
w57 5/1 pp. 285-286 Use Theocratic War Strategy ***A WITNESS of Jehovah was going from house to house in Eastern Germany when she met a violent opposer. Knowing at once what to expect she changed her red blouse for a green one in the very next hallway. No sooner had she appeared on the street than a Communist officer asked her if she had seen a woman with a red blouse. No, she replied, and went on her way. Did she tell a lie? No, she did not. She was not a liar. Rather, she was using theocratic war strategy, hiding the truth by action and word for the sake of the ministry.
In this she had good Scriptural precedent. Did not Rahab hide the Israelite spies by both action and word? Did not Abraham, Isaac, David and others likewise hide the truth at times when faced with a hostile enemy? They certainly did, and never do we read a word of censure for their doing so. Rather, we read of their being termed exemplary servants of Jehovah. Their actions were in line with Jesus’ wise counsel: "Look! I am sending you forth as sheep amidst wolves; therefore prove yourselves cautious as serpents and yet innocent as doves."—Matt. 10:16, NW.
Perhaps some will wonder as to where the line is to be drawn between use of theocratic war strategy in hiding the truth and the telling of lies. First of all, let it be noted that whenever one takes an oath to tell the truth he is obligated to do so. By dedicating himself to do God’s will each Christian has taken a vow or made an oath to do God’s will and to be faithful to him. To this oath he certainly must be true. Likewise, when a Christian is placed on a witness stand he is obligated to speak the truth if he speaks at all. At times he may prefer to refuse to speak and suffer the consequences rather than betray his brothers or the interests of God’s work. And, of course, there is no occasion for use of war strategy when dealing with our Christian brothers. In dealing with them we tell the truth or tactfully remind them that what they seek to know does not concern them.
Lies are untruths told for selfish reasons and which work injury to others. Satan told a lie to Eve that worked great harm to her and all the human race. Ananias and Sapphira told lies for selfish reasons. But hiding the truth, which he is not entitled to know, from an enemy does not harm him, especially when he would use such information to harm others who are innocent.
A great work is being done by the witnesses even in lands where their activity is banned. The only way they can fulfill the command to preach the good news of God’s kingdom is by use of theocratic war strategy. By underground methods the literature is brought into the country and distributed. Would it make sense to hide this literature by one’s actions and then reveal its whereabouts by one’s words when queried? Of course not! So in time of spiritual warfare it is proper to misdirect the enemy by hiding the truth. It is done unselfishly; it does not harm anyone; on the contrary, it does much good.
Today God’s servants are engaged in a warfare, a spiritual, theocratic warfare, a warfare ordered by God against wicked spirit forces and against false teachings. God’s servants are sent forth as sheep among wolves and therefore need to exercise the extreme caution of serpents so as to protect properly the interests of God’s kingdom committed to them. At all times they must be very careful not to divulge any information to the enemy that he could use to hamper the preaching work.
[Footnotes]
For details see The Watchtower, February 1, 1956.