The Senecan Prologue Ghost

Then, too, a filthy whining ghost,
Lapt in some foul sheet, or a leather pilch,
Comes screaming like a pig half-stick'd,
And cries, Vindicta! -- Revenge, revenge!
With that a little rosin flasheth forth,
Like smoke out of a tobacco-pipe, or a boy's squib,
  -- anon., A Warning to Fair Women, ca.1599. prologue

By the time of the writing of Hamlet, it was a tired convention to have a ghost appear at the beginning of the play and, on some occasions, call for the act of revenge which will complete the play. This convention, which seems to have come from the tragedies of Seneca that were rediscovered during the early renaissance, reflects a practice that dates all the way back to such ancient Greek tragedies as Euripides' Hecuba. More often than not, the ghost appears only in the prologue to the play, and does not participate in the action beyond that. Shakespeare is probably making reference to this convention in Richard II.

For heaven's sake, let us sit upon the ground,
And tell sad stories of the death of kings:
How some have been deposed, some slain in war,
Some haunted by the ghosts they have deposed.  (III.ii)