The purpose of the play within the play is to give Hamlet an evidence against Claudius who murdered his father. The play was enacted in order to catch Claudius in his conscience concerning the murder of Hamlet's father.
The play enables us to concentrate on the real play which is being enacted, as Hamlet's eyes were fixed on his uncle's face with the King trying hard not to show by his face what he is feeling. There was a confirmation of Claudius's Guilt. Claudius seems to be frightened at the exit of the player Queen. The shorter play gave the larger play a whole clearer meaning.
Explanation:
"Hamlet" is a tragedy play written by William Shakespeare sometime between 1599 and 1601. The play reveals the murder of Hamlet's father and Hamlet's decision to convict the murderer. Claudius has murdered Hamlet's father in order to become the king and marry the wife.