Lying to Safeguard Halacha
A rabbi is often faced with a dilemma when he is asked a sensitive halachic question by someone who is unobservant, uneducated, or otherwise ignorant of most other halachic principles. In some situations, if the rabbi were to answer the question according to fundamental halachic truth, he might actually, albeit unintentionally, cause his questioner to violate some other halacha. As such, it might just be that a rabbi should sometimes deviate from the actual halacha, and advise a questioner in a manner that better safeguards the greater good of halacha. Below is an example of such a situation.
There was once an unobservant Jew who lost a close relative and decided that he would observe the laws of mourning in the most meticulous manner. He was generally unconcerned with rabbinical rulings, or any other area of halacha for that matter. To him, however, mourning was different and he wanted to properly comply with all the relevant halachot. In this particular situation, the shiva was set to end on Shabbat. Although this fellow knew that the seventh and final day of shiva is only observed for a short period in the morning, he approached his rabbi to confirm that this was indeed the halacha even when a shiva concludes on Shabbat.
The rabbi quickly realized, however, that the reason for the question was that this fellow wanted to correctly confirm that his shiva would be over as of early Shabbat morning, thereby “allowing” him to promptly return to work that same day! As such, the rabbi falsely replied that when the seventh day of shiva falls out on a Shabbat, the shiva continues for the entire Shabbat and does not conclude until after Shabbat ends. This, of course, is simply untrue. Even when the seventh day of shiva falls out on Shabbat, it ends in the morning, just as it does when it ends on any other day of the week.
Did the rabbi conduct himself appropriately by misleading the questioner regarding the laws of mourning in order to safeguard the sanctity of Shabbat?
This question was posed to Rav Yitzchak Zilberstein of Bnei Brak. He replied that the rabbi was entitled to lie in this situation. He based himself on the well-known Talmudic teaching that one is often permitted to lie in order to ensure that peace prevails between people. As such, he reasons, it is certainly permissible to lie in order to distance a person from sin. Similarly, if one must lie in order to prevent someone from harming himself, one may certainly do so. As sin is harmful to the soul, one must prevent others from harming themselves in this way, as well. Therefore, it would be permitted to lie in order to prevent someone from violating Shabbat.
Indeed, there are a number of precedents in the Talmud in which the sages sidestepped the truth in order to distance another person from sin, even if the sin was only of a rabbinic nature. For example, on Yom Kippur one is permitted to begin preparing for the evening "break-fast" meal from the afternoon onwards, and one may even violate certain rabbinical prohibitions in doing so. The sages were lenient with this in order to ensure that the evening meal would begin promptly after the fast.
Nevertheless, Rabba was concerned that people would be negligent with this leniency and begin preparing the evening meal even in the morning hours of Yom Kippur. As such, he fabricated a story of having received a letter from the sages of Eretz Yisrael in which they wrote that all such preparations – even in the afternoon -- were forbidden by decree of Rav Yochanan. Of course, none of this was true. Rabba merely took the liberty of lying in order to ensure that people would not begin preparing the evening meal when doing so would be truly forbidden.
There is another Shabbat-related example which further illustrates that it is occasionally proper to lie in order to safeguard halacha. If one is asked what time Shabbat begins, one is permitted to lie and respond with a time that is slightly earlier than the time it truly begins. However, even in this situation one may not purposely mislead others. One may only lie if there is a credible reason to believe that the person might procrastinate and thereby possibly perform forbidden activities after Shabbat begins. There are other such examples, as well.
 This story is cited in Veharev Na, Vol. I Bereishit.
 Shabbat 115a.
 Shabbat 139a; Keritut 8a; Gittin 62a.