Yorick was King Hamlet's jester. When Hamlet learns of this from the gravedigger and Shakespearean clown, this amazes him because of the fond and good memories of him and his personality, jokes, "merriment", etc. he had of Yorick when Hamlet was a child.
Sadly, now Yorick is nobody. Yorick is dead.
However, when he was alive, he was King Hamlet's jester. He was also someone Hamlet knew. When Hamlet encounters Yorick's skull, he plays with it, then uses it as an occasion to reflect on mortality. In such capacity, Yorick's skull foreshadows Hamlet's own death (see Act V.i for their interaction).
Yorick was the king's jester. He is an omen of death and the skull foreshadows the death of hamlet in the near future. Besides he also represents the temporariness of life.
He also serves the bring back a memory from the childhood of Hamlet; a time when he was not plagued by the task of revenge. Unconsciously he may be wanting to return to that state of freedom; an element which is also a prelude for his death.
He is already dead before the starting of play begins. He was the jester (court fool), of the former king. Hamlet saw Yorick's skull during the graveyard scene when he was strolling with Horatio in Act V and during their conversation, he said:
A pestilence on him for a mad rogue! 'a pour'd a flagon
of Rhenish on my head once. This same skull, sir, was, sir,
Yorick's skull, the King's jester.
This? [Takes the skull]
Alas, poor Yorick! I knew him, Horatio, a fellow of infinite
jest, of most excellent fancy. He hath bore me on his back a
thousand times, and now how abhorr'd in my imagination it is!
My gorge rises at it.
It shows that Hamlet have a very strong relationship with Yorick and is very sad by looking at the skull as he still remembered the times they spend together, the vivid memories