Why did the ghost appear to Hamlet in Shakespeare's play Hamlet, and what was the conversation about?
The reasons for the ghost's appearance is actually very clearly spelled out in the final scene of the first act. The ghost begins to explain his appearance to Hamlet in his first long speech starting at line 13. There are a couple of different reasons why the ghost appears.
One thing that the ghost explains is that he is "[d]oom'd for a certain term to walk the night, / And for the day confined to fast in fires" until all of the "foul crimes" he committed while alive are "purged away" (I.v.14-17). In other words, one reason why he is appearing is because it is part of his punishment to keep roaming the earth at night; although, we never actually learn what "foul crimes" King Hamlet was guilty of.
The second reason why King Hamlet's ghost has appeared before Hamlet is explained in the next line he speaks; in this line, he asks Hamlet to "[r]evenge his foul and most unnatural murder" (29). The ghost further explains the murder in lines 36 through 45 as well as in his longer speech beginning at 47 and ending at 84. He explains that his own brother, Hamlet's uncle and the current king, crept into King Hamlet's orchard while he was taking his customary nap and poured a vile poison into his ears that killed him "swift as quicksilver" (71). Hence, the second reason why the ghost appears and specifically addresses Hamlet is because he is asking Hamlet to avenge his own father's death by killing his uncle.
The "ghost" in question is, of course, the specter of Hamlet's father, the late king of Denmark. He returns to Elsinore to demand that his son avenge his murder at the hands of Claudius. When the ghost reveals this fact to Hamlet, he responds by suggesting that he suspected as much all along, saying "O my prophetic soul!" The ghost describes the details of his murder, which Hamlet later has the players reenact in order to ascertain that his uncle is, in fact, guilty of the crime. He beseeches Hamlet to avenge his death, saying:
If thou hast nature in thee, bear it not.
Let not the royal bed of Denmark be
A couch for luxury and damned incest.
The ghost, however, does tell Hamlet not to exact revenge on his mother, but rather to leave her to be judged by God and her own conscience. So the meeting between Hamlet and the Ghost sets the entire plot of the play in motion. Hamlet is sworn to revenge, which he finally achieves in the ultimate scene of the play.