The prince, Hamlet, is confused/uncertain over death and suicide. He's kind of sure about the pain, sorrow, and unfairness of life; except he thinks that suicide is not the answer to end all the pains. Knowing, that after-life or consequences of a suicide can be worse. What he meant was, "to live or not to live?", "to die or not to die?", or "to suicide or not to suicide?"
Usually, people use this phrase when they are uncertain and confused over anything.
hopefully my answers help!
(if my answers helped you tell me, therefore I know.. that I did them correctly. anyways, have a great day/night!)