In Shakespeare's Macbeth, the porter scene that comes after the killing of Duncan makes the reader laugh. The porter is a strange gatekeeper. It is also a metaphor for the gates of hell. When the porter enters, it is a transition from a supernatural story to a more dramatic story.
Macbeth's porter scene functions as a comic relief after King Duncan is killed. The troll-like gatekeeper makes the audience or reader laugh with his drunken banter, and relieves the tension of the killing in the prior scene. He casts light on Macbeth's internal torment. For example, in the manner of dark comedy he makes fun of Lady Macbeth's fears. This scene makes people laugh because of the porter's soliloquy.
On a more serious side, the porter's drunken state gives rise to one of the second act's main metaphors - the house of Macbeth as the gates of hell. The Porter's soliloquy contains satanic images, and he views himself as gatekeeper. Shakespeare views Castle Macbeth as the home of death and corruption, because of the Lady and the murderous acts of its Master. The porter scene symbolizes that everyone who comes into the castle and tries to stop Macbeth ambition have entered hell. Even though this scene makes audiences laugh, it also shows how Shakespeare feels about Macbeth's murderous behavior.
I agree with kimfuji, but there is more:
The Porter scene is a reference to an English Mystery Play called the "Harrowing of Hell." In the play (which was enacted throughout the British Isles in the 14th-16th centuries), Christ comes to hell to save those souls who came before his time.
The Porter is the devil who opens the gates of hell. And who is it that was knocking and woke up the Porter and wants to gain admittance? It is Macduff who will eventually leave and return from England to save Scotland.
Thus the Porter scene is a major turning point in the play: it adds humor which intensifies the horror of the murder that has just taken place, it reminds us of the contradictory nature of the entire play (the Porter's lines swirl with opposites), and it points to the the punishment of evil doers and the coming of a time of salvation.
The porter scene plays a very vital role in Shakespeare's play Macbeth. It serves the purpose of dramatic relief in the play, as it figures immediately after the gruesome murder of Duncan by Macbeth. While reading the play, the tension in the mind of the reader shoots up to a high degree till the point of the cold-blooded and well-planned murder of Duncan. The way the porter talks and receives the visitors to the castle of Macbeth creating the impression of the porter being at the hell gate symbolically suggests the conversion of Duncan's castle into a virtual hell and creates a certain amount of humour in the play which the reader is in dire need of. A similar stance providing the reader with dramatic relief figures again later in the play through the prattling of children prior to the murder of Macduff's wife and children.
Thus the role of the porter is structurally integral to the play providing the reader with a much-needed scene that lessens the tension in the mind of the reader.