The porter scene in Macbeth, written in prose similar to the prose of Lady Macbeth seems to underscore her insanity while providing some comic relief from the somber tone of the Lady's madness. In addition to this comic relief afforded the audience by the character of the porter, his repeated use of the word equivocation serves to enhance the development of the theme of ambiguity--"fair is foul, and foul is fair"--in Macbeth as well as the intentionally ambiguity of Macbeth and Lacy Macbeth who lure Duncan to their castle only to murder him. Interestingly, (per one of my scholarly associates, shaketeach) the allusion to the eqivocator is a reference to the Jesuit priest, Father Henry Garnet, who revealed a couple of the plotters involved in the Gunpowder Plot and was known as the "great equivocator." This may be the man the porter refers to when he says,
Faith, here's an equivocator that could swear in both the scales, against either scale, who committed treason enough for God's sake, yet could not equivocate in heaven. (3.2.8-10)
So, in a sense, there is some foreshadowing of Macbeth's end with the porter's speech.
Many critics have assumed that the so-called Drunken Porter Scene (Act 2, Scene 3) was inserted for comic relief. It is funny, but it has a serious purpose. The Porter has to explain why there has been such a prolonged knocking at the gate. What is important is the knocking. When the Porter finally opens the gate, he explains to Macduff that he and all the other members of the household staff were too drunk to respond.
Macbeth had planned to be pretending to be sound asleep when Duncan’s body was discovered. His wife tells him:
Hark, more knocking.
Get on your nightgown, lest occasion call us
And show us to be watchers.
But Shakespeare wanted Macbeth to be present at the scene of the crime. The knocking forces Macbeth to come down in his nightgown to find out why nobody is opening the gate. This brings him and Macduff together for the only time before their death duel at the end of the play.
The discovery of Duncan’s body is much more dramatic than it would have been without Macbeth’s presence. The audience witnesses Macbeth’s apprehension and understands how he is suffering internally while trying to appear calm and natural.
No doubt the drunken porter elicited a great deal of laughter, especially if a talented clown had the role. Shakespeare knew that comedy would help to beguile his audience and keep them from asking themselves such questions about the plot as:
Why wasn’t Macduff sleeping inside the castle?
Why didn’t Duncan appoint someone else to wake him in the morning, someone such as Banquo who would be accommodated inside the castle?
Why did Macbeth and his wife permit his entire household staff to get so drunk when the King himself was their guest?
Why wasn't Macduff furious when the Porter finally let him in?
Shakespeare had to hope that his audience wouldn’t ask such questions because he wanted Macduff to discover the body and he wanted Macbeth to be present when he did. So the “comic relief” had a very serious purpose.
The idea of having Macbeth appear in his nightgown probably inspired Shakespeare to have everybody appear in nightgowns when Macduff shouts, "Ring the alarum bell" and then calls to all the sleeping guests:
As from your graves rise up and walk like sprites
To countenance this horror.
They will all look like ghosts (or sprites) when they appear onstage in white nightgowns. These sprites will include Banquo, Fleance, Malcolm, Donalbain, Lady Macbeth, and others. It will be a striking visual scene.
1. The speech is a comic relief after a sombre climactic point is reached in the play with Macbeth's killing of Duncan.
2. It is a transition in the sense that it introduces prose in what is predominantly blank-verse play.
3. It is a choric commentary on the tragic condition, defined by the play---the interplay of mental evil and the temptations that push it from the outer world.
4. The destiny of the entrants to inferno all echo Macbeth's. This is a great example of tragic presentiment and anticipation. It sketches a tragedy of ambition, greed and also equivocation, which is one of the most significant themes in the play, especially in the tricky use of language that we find with the witches.
5. It is a theatrical necessity in so far as the two actors playing Macbeth and Lady Macbeth need time to change their blood-stained clothes before reappearing in front of Macduff and company.
6. It is an important site to determine the time of the composition of the play with the topical allusion to the episode of the gunpowder plot.
7. The comparisons between the tipsy porter and the devil-porter and Inverness (inverted into) inferno---they only highlight the moral depravity involved in the event of murder, which has just taken place.
The Porter scene has quite a few purposes both dramatically and logistically. Most simple of all is the fact that it allows the actor playing Macbeth to wash the blood from his hands, after Duncan's murder, in time for the next scene.
Also, Shakespeare is creating comic releif. He pauses from the 'action' to make the audience laugh, especially with the Porter's 'lechery' speech:
"Lechery, sir, it provokes, and unprovokes: it provokes the desire, but it takes away the performance"
These lines are about alcohol's effect on the male libido and, by using them to make the audience laugh, Shakespeare releives the tension they are feeling after the murder. Simillarly, by allowing the audience a moment of easy-going comedy, Shakespeare provides the audience with time for reflection on the events they have scene. If Shakespeare had taken moved the plot straight into more 'heavy' scenes, then perhaps some of the more subtle moments of Duncan's murder may have escaped the audience's notice.
On a symbolic level, by pretending to be the porter of the gates of hell, the Porter is asserting that Macbeth's castle is indeed hell. It also shows that, in murdering Duncan, Macbeth has sold his soul to the devil (something he later admits).
I think, also, the Porter is foreshadowing the relentlessness of Macbeth's forthcoming guilt. This is not only through the premise of Macbeth's castle signifying hell but als in the line "Knock, knock. Never a quiet..." this links to Macbeth's quote after he has killed Duncan "Macbet hath murdered sleep". This is a personal opinion and may not have been intentional but it is certainly important to remember that the Porter is much more than a comic device.
Hope this helps.