This quote is in Act 1, Scene 4. Horatio, Marcellus, and Hamlet are waiting for the ghost to appear. The ghost finally appears and Hamlet addresses it. Hamlet tries to get the ghost to tell him why he is there in the first place:
Why thy canonized bones, hearsed in death,
Have bursed their cerements, why the sepulchre
Wherein we saw thee quietly inurn'd,
Hath oped his ponderous and marble jaws
To cast thee up again. (I.iv.50-54)
The ghost does not respond verbally but beckons Hamlet to follow him. Horatio and Marcellus both implore Hamlet not to follow the ghost. Since Hamlet is still full of grief and depressed as a result of his father's death (murder), he finds little to be happy about. Although warned not to follow the ghost, Hamlet remarks that he doesn't value his life very much (on account of his grief and melancholy), therefore why should he fear the ghost. Hamlet uses hyperbole, an exaggeration, saying he doesn't value his life even at the price of a pin. In other words, Hamlet is saying he has nothing to lose. If he valued his life, he might be a little more cautious about following a ghost. Although Hamlet is quite depressed, it does seem to be an exaggeration (hyperbole) to say that his life isn't even worth the price of a pin.