What is Osric's function in Hamlet?
With Queen Elizabeth's love for Shakespeare's plays, the bard may have inserted Osric into the drama in order to provide some satire for Her Majesty and other Englishmen. For, Osric is a fashionable and flashy courtier typical of the Elizabethan court, rather than the Danish, and he earns a place in court because as Hamlet tells Horatio "he hath much land and fertile" (5.2.86). In his sense of self-importance, Osric, however, goes too far in imitation of witty dialogue by being extravagant and even absurd. His affectations such as his ridiculous formalities, tarnish his efforts at courtliness and politeness, as well. His sycophancy is exposed when Hamlet says it is cold and Osric, who has previously stated that he has taken off his hat because it is hot, agrees; then Hamlet says it is hot, and Osric immediately and slavishly concurs with this opinion:
HAMLET Put your bonnet for its right use. 'Tis for the head.
OSRIC I thank your lordship, it is very hot.
HAMLET No, believe me, 'tis very cold; the wind is northerly.
OSRIC It is indifferent cold, my lord, indeed.
HAMLET But yet methinks it is very sultry and hot for my complexion
OSRIC Exceedingly, my lord; it is very sultry, as 'twere-I cannot tell how.... (5.2.93-98)
In addition to his role as a courtier to be satirized, the reader may well infer that Osric was privy to the final treachery against Hamlet. For, as Laertes dies he says to the courtier,
Why, as a woodcock to mine own springe, Osric;
I am justly killed with mine own treachery. (5.2. 326)
and Osric receives this confession with no noticeable astonishment.
Osric is an overdressed, pretentious, "dandy" who is also a cause for some hmuor. His task is to deliver Laerte's challenge and to creaate another comic scene before the final scene showing all the deaths of the major characters,(except Horatio).
What is Osric's function?
While Osric has several minor functions in the play (he is, for example, one of many foils used to show Hamlet's mind), his main purpose is to deliver the challenge to the duel with Laertes.
I think this answer is essentially correct. Shakespeare needed someone to deliver the challenge, to explain the complicated wager, and also to handle the foils and to act as referee. Notice how in Act 5, Scene 2, Hamlet claims to have made a hit and calls for "Judgment" when Laertes says, "No." Osric declares: "A hit, a very palpable hit."
Once Shakespeare invented Osric to serve his practical needs, he also made him an amusing character who seems like a real person rather than a mere walk-on factotum or gofer. Osric is such an ineffectual dandy that he is unable to separate Hamlet and Laertes when Claudius calls, "Part them. They are incensed." Osric is probably afraid to get between them.
Osric personifies everything that Hamlet hates in the Danish court. He possesses an artificial personality and like Polonius, it is clear that he can be easily manipulated by Claudius. He is also used as a device to show the interaction between Hamlet and Horatio.
He is also present to introduce a touch of humour to the play,ironically just before the death of several major characters.
He is an affected courtier who plays a minor role as the King's messenger and as umpire of the fencing match between Hamlet and Laertes.