Throughout the play, Hamlet is preoccupied with thoughts of mortality and the fleeting nature of human life. He contemplates suicide as a means to escape the pain and suffering he experiences, but is hesitant due to his fear of what may come after death. The ghost's description of the afterlife as a place of "undiscover'd country" only adds to Hamlet's anxieties, as he cannot be certain whether it holds salvation or eternal punishment.
Hamlet's obsession with death leads him to ponder the nature of existence and the meaning of life. He engages in philosophical discussions with other characters, such as his friend Horatio, about the soul, the afterlife, and the consequences of our actions. Hamlet's contemplation of these profound questions reflects his deep-seated existential crisis, which is further intensified by the presence of the ghost.
In conclusion, the ghost in Hamlet acts as a catalyst for Hamlet's existential contemplation, causing him to dwell morbidly on the afterlife. The ghost's revelations and Hamlet's subsequent exploration of life and death form a central theme of the play, adding depth and complexity to Hamlet's character and the overall narrative.