A player may declare his ball to be unplayable at any time - except when it is in a water hazard.
Even if another golfer considers it to be playable, the player is the judge.
Sometimes it might be in a player's interest to do this - when right up tight to the face of a bunker for instance.
Once a player has done this he has three options:
Play a ball as close as possible to the spot where the original was played
Drop a ball within two club lengths of the spot where the unplayable ball lay but no nearer the hole
Drop a ball on a line running from the hole through the spot where the unplayable ball lay as far back as he or she likes