The theme of lying as a necessary evil plays out in the following ways in Macbeth. If you are an evil character, such as Macbeth or Lady Macbeth, lying is a necessary evil to accomplish your goals but such lying leads to a bad end. Macbeth and his wife, for example, have to lie and pretend to be offering Duncan all their hospitality and protection when he comes to stay with them when in fact, they are planning to kill him.
This deceit seems necessary to them, because they can't afford for anyone to be tipped off as to their real intentions. Once Macbeth completes the murder and becomes king, more and more lying seems necessary to cover up the original deed. As Macbeth commits more and more murders, he has to lie more and more to keep the bloody trail from coming back to him.
In Macbeth's case, these lies, which are only necessary for an evil purpose, harden Macbeth to the point he becomes dead inside and loses all joy in life. Being King of Scotland, which he thought would bring him the greatest happiness, brings him nothing but misery. As he states in his final soliloquy, for Macbeth, life has become meaningless:
It is a tale
Told by an idiot, full of sound and fury,
Lady Macbeth, too, suffers for her evil lies. Guilt overwhelms her, and she eventually commits suicide.
The good characters who oppose Macbeth also find lies a necessary evil in order to overthrow him. Malcolm is the chief example of a person who lies in order to serve the greater good. For example, he tells untruths to test Macduff's loyalty to Scotland. He pretends to be a horrible person who wants to take the crown from Macbeth only so he can pillage and create chaos in the land. For instance, Malcolm says,
Devotion, patience, courage, fortitude,
I have no relish of them
... Nay, had I power, I should
Pour the sweet milk of concord into hell ...
When Macduff finally recoils in horror and says he can never support Malcolm if he is such a terrible person, Malcolm says he is truly a good person. He informs Macduff that he had to make sure his first loyalty was to the good of Scotland, not the good of Malcolm. In this case, lying is a necessary evil that has a good end.