Title is pretty self-explainatory.
King John II, of France, was captured by the English in 1356 after a battle. The country could not rule itself, so a regent was almost immediately declared, in this case, King John's son, the later King Charles V. Charles later became king in 1364, but as regent he needed to pay the ransom. Paying a random wasn't expected to be immediate, so Charles instead raised taxes across the country. This caused widespread outrage, with rebellions from all classes, including the peasant class and the nobles.
He was to pay four million gold crowns for his fsther's ransom, but King John II would be released after paying one million. This was partly for practical reasons- they needed a stable country to be able to pay back the money. To ensure ransoms would be paid after release, two of his sons, and some nobles, were given as hostages (one of the sons eventually escaped, in 1362, forcing King John to give himself up).
But the ransom payment didn't just fall to Charles. Despite being in captivity, King John was still very important and during his captivity, he negotiated for peace. This was when it was decided, agreed to by King John, that most of Western France, as well as the four million, was to go to England. This was impossible for Charles. He was dealing with political instability, lack of support, rebellions. He could not physically afford this ransom. He had to declare it invalid.
The war therefore restarted. King Edward (of England) invaded France. He was not as successful as he had assumed he would be. Edward could not persuade Charles to join him in a decisive battle. This was a stalemate. Finally, King Edward agreed to reduce the terms of the treaty, so only three million crowns would be paid, and only a third of Western France would go to England, agreed to do in the Treaty of Brétigny.
He was released. King John was allowed to sail back to France, in exchange for the forty hostages, including the nobles and two of his sons as I already mentioned. They could not let the random be paid by an indefinite amount of time, this was obviously very impractical, so King Edward set a date of six months for the random to be paid. This did not happen. The instability, the devaluation of the currency in an attempt to raise money, the ineffective ruling of Charles as regent, meant France was much weakened. They did not pay the ransom in six months and took years instead, but ultimately England wanted the money, so that was accepted. They might well have fully paid it back in time if it had not been for King John II's son, Louis, escaping. King John therefore voluntarily returned, to prevent the ransom increasing or even another invasion.
So how can a king ransom himself? Firstly, the regent would be able to raise money, through taxes usually. Secondly, for most of history, it was impractical to suggest money be paid right away, meaning that the majority of the ransom would be paid once the King had left captivity, with hostages to ensure the ransom would be paid.
Sources: Agincourt (Christopher Hibbert),
The Crecy War: Military History of the Hundred Years War from 1337 to the Peace of Bretigny, 1360 (Alfred Burne),
Poitiers 1356: The Capture Of A King (David Nicolle),
Royal taxation in Fourteenth Century France, The Development of War Financing 1322-1356 (John Henneman).