Sleeplessness is part of the witches' plan to ruin Macbeth.
Here, from Act 1, Scene 3, is what the intend:
I will drain him dry as hay:
Sleep shall neither night nor day
Hang upon his penthouse lid;
He shall live a man forbid.
Weary se'nnights nine times nine
Shall he dwindle, peak, and pine;
Though his bark cannot be lost,
Yet it shall be tempest-tost.
Sleep deprivation can drive one mad, and Macbeth will be on his way soon. Just after the murder of Duncan, when Macbeth hears that he will be cursed with lack of sleep, he speaks this pathetic praise of what he is about to lose (Act 1, Scene 5):
—the innocent sleep,
Sleep that knits up the ravell'd sleave of care,
The death of each day's life, sore labor's bath,
Balm of hurt minds, great nature's second course,
Chief nourisher in life's feast—
One can assume that from the murder on, Macbeth has lots of trouble sleeping.
The motif of sleeplessness first occurs in Act 2, scene 2. After Macbeth kills Duncan and returns to his chamber, we can see that he is already in the grip of guilt and severe anxiety. He tells his wife, "There's one did laugh in's sleep, and one cried, “Murder!" (30). He tells her that the servants were crying out in their sleep with "God bless us" and "Amen", as if they had seen him murder the king. Yet when Macbeth tries to pray he could not, a fact that distresses him greatly.
When Lady Macbeth urges him not to dwell on the matter ("consider it not so deeply"), he seems unable to hear her. He continues to recount his experience: "Methought I heard a voice cry “Sleep no more! Macbeth doth Murder sleep--” (35-36) and “Glamis hath murdered sleep, and therefore Cawdor Shall sleep no more. Macbeth shall sleep no more" (43).
Macbeth next mentions sleeplessness in Act 3 scene 2, just after her orders the murder of Banquo and his son Fleance. Although he has no idea that the plan will go awry, he tells Lady Macbeth it is better to be dead, like the King, than to lie in bed tortured by doubts and fears--a suggestion that he has been suffering in this way himself. Coincidentally, his statement mirrors one that Lady Macbeth makes while alone on the stage (see Act 3 scene 3 ll 6-9). Later in the act, after Macbeth has made a spectacle of himself reacting to Banquo's "ghost", Lady Macbeth tells him that he lacks sleep, "the season of all natures" (170).
Ironically, it is next Lady Macbeth who next has trouble with sleeping--or at least with sleeping while not walking and talking at the same time. In Act 5, scene 1, the Doctor and Gentlewoman are bewildered to witness her episodes of sleepwalking, which are accompanied by such morbid ramblings about blood, guilt, and murder that the Doctor claims that her ailment can only be cured by God: "More needs she the divine than the physician" (68).
The subject of Macbeth not sleeping is first introduced in Act 2.2 of Shakespeare's Macbeth, when he hears voices tell him that he shall sleep no more, and that he has murdered sleep.
He hears these voices right after he kills King Duncan. And notice that after he demonstrates guilt by obsessing over the blood of Duncan being on his hands, and his admission that he could not join in by saying "Amen" to a prayer he overhears, the knocking occurs and he flees to his bedchamber. But only minutes pass before he is back on stage killing the two grooms--Macbeth doesn't sleep that night.
Lady Macbeth has trouble sleeping during her sleepwalking scene, of course. In Act 5.1 she, too, suffers from guilt and sleepwalks and obsesses over the blood on her hands.