Different general approaches to ethics may provide different answers to this question. Speaking very broadly, there have been three basic approaches to ethical theory. Kant (and others like him, called "deontologists") will argue that the correct way to view ethics is by formulating rules that may be applied universally. In this approach, dishonest will always be bad--though in some cases it might be the lesser of two evils. J. S. Mill (and others like him, called "consequentialists" or more narrowly "utilitarians") will approach ethical questions with a view to what consequences will flow from the act in question (or else from the rules they formulate that will tell us how to act). In this approach, lying can sometimes be good because it will have consequences that have greater utility, all things considered, than telling the truth. Aristotle (and others like him, called virtue theorists) will say that the primary bearer of value is the character of the agent, and not the actions the agent performs. For a virtue theorist, lying would be OK (or even the right thing to do) when and if a virtuous person would lie in that situation. A good example of a discussion on this very point--from a virtue theoretical point of view--can be found in Plato's Republic Book I (331a-c). Plato claims there that it would be wrong to tell the whole truth to someone who was out of his mind (and who might, therefore, react to the truth in an irrational or possibly dangerous way). For a virtue theorist, one-size-fits-all moral principles will always have exceptions, and the sort of case you seem to be worried about may be of this sort. For such exceptional cases, according to virtue theory, good ethical judgment will always be required and can only come from adequate training and habituation.
Read another response by Nicholas D. Smith
Read another response about Ethics
Truth for the sake of honesty, or lies for the sake of harmony - can there be situations where dishonesty is morally sound?