Is it ever right to lie? In the following passage, we have a prostitute, Rahab, telling a straight lie to the King’s officers. The King’s officers were looking for Joshua’s spies, and instead of directing them to the right place, she deceived them.
2 The king of Jericho was told, “Look! Some of the Israelites have come here tonight to spy out the land.” 3 So the king of Jericho sent this message to Rahab: “Bring out the men who came to you and entered your house, because they have come to spy out the whole land.” 4 But the woman had taken the two men and hidden them.
She said, “Yes, the men came to me, but I did not know where they had come from. 5 At dusk, when it was time to close the city gate, the men left. I don’t know which way they went. Go after them quickly.
You may catch up with them.” 6 (But she had taken them up to the roof and hidden them under the stalks of flax she had laid out on the roof.) 7 So the men set out in pursuit of the spies on the road that leads to the fords of the Jordan, and as soon as the pursuers had gone out, the gate was shut. – Joshua 2:2-7
Was it moral for her to do that? What we do know is that at the end of the story Joshua praises and honoured her for her part in saving the lives of the Israelite spies. This is the verse,
22 Joshua said to the two men who had spied out the land, “Go into the prostitute’s house and bring her out and all who belong to her, in accordance with your oath to her.” 23 So the young men who had done the spying went in and brought out Rahab, her father and mother, her brothers and sisters and all who belonged to her. They brought out her entire family and put them in a place outside the camp of Israel.
24 Then they burned the whole city and everything in it, but they put the silver and gold and the articles of bronze and iron into the treasury of the Lord’s house. 25 But Joshua spared Rahab the prostitute, with her family and all who belonged to her, because she hid the men Joshua had sent as spies to Jericho—and she lives among the Israelites to this day. – Joshua 6:22-25
In fact, in James 2-24-25, and Hebrew 11:31 she is praised. Nowhere in the Old Testament (or New Testament) do we see God, or Prophets condemning her falsehood against the King’s officers. Moreover, even Biblical commentators agree that deception can be used in order to repel evil.
Peter Pett’s Commentary on the Bible
Rahab is often criticised for lying. This raises an interesting moral question. When only two courses
are open to someone, both ‘sinful’, does that mean that they have no alternative but to sin? The truth is that one of the two actions must be the right one in the circumstances, and therefore morally right in that particular case. Here the truth would have immediately sentenced these brave men, who were there in the service of God, to death. That would have been sinful. Was it more sinful to lie?
One of the courses had to be chosen, thus one was right (silence would have been just as bad). To be the direct cause of the men’s death would have been grossly wrong. If we accept that, then the lie was right in this particular case. Her contemporaries would not have cavilled about that. Rather they would have thought that her greater sin was her treason. 
A Carpenter’s View of the Bible – PhD Charlie March
A big deal has also been made about Rahab’s lying incident to the king’s men concerning the whereabouts of the spies, as if it would be a more righteous thing to honestly give them up to torture and a slow death. Criticism for the sin of Rahab’s lie is similar to when the Christian Corrie ten Boom lied to the Nazi SS about where the Jewish family was hiding behind a false wall in her house. Again, along with the sexual innuendo business, this is ridiculous.
I am not justifying lying, but this is a matter of moral priority. In these few, extreme cases. Deception against evil may be necessary to save lives. A tough moral compromise may be necessary to preserve life. 
M. David Sills
Christians unfamiliar with the creative access approach may struggle with the ethics involved. After all, the Bible commands Christians to be the best citizens in the land, to be obedient, and to respect the leaders and governments God has established (Romans 13:1-7; 1 Peter 2:13-17).
However, we also read of the apostles telling governing authorities that they must obey God rather than man (Acts 5:29). Moreover, God has commended us to go and make disciples of all nations (Matthew 28:18-20).
Clearly, there is a balance; but what is it? Must believers always tell the truth, the whole truth, and nothing but the truth? An old adage says, ‘All’s fair in love and war.’ We see an example of this in Joshua 2 where Rahab lies to protect the Hebrew spies and is rewarded for it. In fact, she is even mentioned in Hebrew 11’s ‘Hall of Faith.’
There are times when armies lie and send misinformation to the enemy about a frontal attack, only to move quickly to new positions and attack the enemy flank. Such deception may spare countless lives, and we reward the officers for their wise strategy. … Likewise, since we live in a fallen world, many Christian missionaries consider the spiritual warfare they face as a result of kingdom work to be justification for lying to the government in the countries where they work. 
James T. Murphy, Jr.
That matter occurs between verses 2-7. The King issue of whether or not Rahab was right or wrong in what she said to the King’s inquiry about the spies is often the center of debate in this passage. Was Rahab justified in telling a bald face lie or not? There’s no around it, she told a lie. But what do we do with her actions? Are we to be practitioners of situational ethics? Let me offer the suggestion that the end justified the means. Life for both Rahab’s house and a generation of Hebrews was preserved for the betterment of humanity.
The will of the King was opposite than the will of God. Rahab’s actions were for the greater good. There are times when ‘By any means Necessary’ we have to make decisions that may not appear ethical or of honesty on the surface. Those decisions are generally surrounding issues of life and death.
Thank God, Rahab chose life which secured her life as well. One thing is certain, when you decide to conquer by any means necessary, people will question your motives to the extent of criticism. We can only imagine what criticism Rahab experienced resulting from her decision.
However, when the invading Israelites entered Jericho, the scarlet thread within Rahab’ window became the equal element of ‘any means necessary’ which preserved her family (2:17-18, 21). Might we further add that Rahab knew just where to send these spies for protection until the pursuers had concluded their search (2:22).
Yes, Rahab had supplied these men with unexpected help. Ultimately, when we cooperate with the will and plan of God the promised victory is provided for even God moves with a ‘By any Means Necessary’ mentality. 
The Bible Answer Book for Students – Hank Hanegraaff
…while the Bible never condones lying for the sake of lying, it does condone lying in order to preserve a higher moral imperative. For example, Rahab purposed to deceive (the lesser moral law) in order to save the lives of two Jewish spies (the higher moral law). In the same way, a Christian father today shouldn’t hesitate to lie in order to protect his wife and daughters from being reaped or murdered.
Finally, there is a difference between lying and not telling the truth. This is not merely a matter of semantics; it is a matter of substance. By way of analogy, there is a difference between unjustified and justified homicide. Murder is unjustified homicide and is always wrong. Not every instance of killing a person, however, is murder. Capital punishment and self-defence occasion justified homicide.
Similarly, in the case of a lie (Annanias and Sapphira, Acts) there is an unjustified discrepancy between what you believe and what you say, and so lying is always wrong. But not telling the truth in order to preserve a higher moral law (Rahab, Joshua 2) may well be the right thing to do and thus is not actually a lie. 
 Peter Pett’s Commentary on the Bible
 A Carpenter’s View of the Bible [Copyright 2010] By PhD Charlie March page 77
 Reaching and Teaching: A Call to Great Commission Obedience [Copyright 2010] By M. David Sills page 132
 Crossing Your Jordan: Handling Life’s Many Turbulent Moments [Copyright 2010] By James T. Murphy, Jr. page 28
 The Bible Answer Book for Students [Copyright 2007] By Hank Hanegraaff page 162 – 163