There is a clear and deliberate use of asides in the first section of Act 5 scene 2 when Hamlet and Horatio are together and then joined by Osric who is a courtier to King Claudius. One of the common things about courtiers is that they serve at the whim of the king or the royal family and therefore are completely at their mercy. They have a very specific role to play and ultimately it is their duty to be clever, witty and sharp, yet always do what will please their lord. The asides between Hamlet and Horatio reveal how the two men are making fun of this courtier for his formal pretensions and his fawning behavior. They are having their own conversation about him right in front of him.
When he first comes Hamlet doesn't appear to recognize him and asks Horatio if he knows the man. Perhaps Hamlet does know him, but is belittling him a bit by acting as though he never gave Osric any thought. This is suggested by Hamlet's next aside when he tells Horatio that it "tis a vice to know him" and goes on to make fun of his connection to Claudius. The rest of the asides aim to make fun of how wordy and witty the courtier is trying to be. They are making fun that he is trying so hard to sound smart that he is actually failing in the endeavor.
The whole small scene serves as a brief reprieve from the heaviness of the cemetery scene and subsequent conversation and it also provides Hamlet with the fencing challenge from Laertes which leads to the tragic conclusion of the play.