Hamlets mistake is that he believed in something like a ghost, that doesn't exist. The second he believed in something irrational, he was doomed. Those are just delusions imagined by the living. Once you're dead, that's it. The dead don't return, nor do they hear our wishes. It's all an illusion. Things you forgot to say, things you couldn't say... they want ghosts to hear them, so they dream one up. It's also possible that people imagine their desire as ghosts.