Pope John Paul II began his life as Karol Wojtyla but gave up his original Polish name when he became pontiff. Many speculate that he chose "John Paul" to honor his predecessor, Pope John Paul I, who passed away after barely a month in office. This previous pope had selected the unusual double name as a combination of two earlier popes.
When a man is elected pope, the cardinal dean asks him two questions. First, the candidate is asked if he accepts the office. If that's a "yes," he's then asked what name he wants to be known by as pope. Presumably, he's thought about this beforehand, because immediately, the two masters of ceremonies draw up documents to announce the new pope and his name.
Choosing a papal name isn't required by Catholic ritual, but it's been tradition since the year 1009. The first pope to change his name was John II in 533. His birth name was Mercurius or Mercury -- which was also the name of a pagan god and not so good for the head of the Christian church. New papal names started to become popular, but they weren't absolute. The last pope to keep his given name as pope was Marcellus II in 1555.
These days, a new pope often picks the name of his favorite saint or pope to be his papal name.