The actual history of this is very interesting - and murky in parts.
Sweden had an elected monarchy until 1543 where the aristocracy gathered and decided who would be the new King (a bit like electing a Pope) However King Gustav Vasa managed to get a new law passed that all future kings would be from the house of Vasa - thus making it a hereditary monarchy.
However the terrible events of 1809 changed everything. Sweden was a large Eastern European power but fought a disastrous war against Russia and lost huge swathes of Swedish territory (the whole of present day Finland and parts of Russia). The Swedes were furious and a military coup exiled the royal family from Sweden but supported an uncle to succeed him.
One result of the disastrous way was to force Sweden into the Napoleonic Continental system for trade, giving Napoleon greater influence. However, a new constitutional crisis emerged when the new King, Karl XIII, suffered a heart attack in 1809, the same year he took power. Although he survived he became a permanent invalid with a regent needed. This triggered a succession crisis as his own children died as newborns. So it was decided that he would adopt a Danish prince - but then he also died
Then it becomes very murky. A Swedish envoy was sent to get Napoleon's blessing to put another Danish prince on the throne - but somehow he can home having offered the throne to one of Napoleon's generals - a man of no noble birth and the son of a lawyer from Pau - Jean-Baptiste Bernadotte .... and this is how the Bernadottes obtained the throne of Sweden and Norway.
It backfired a bit on Napoleon though - he thought he was getting a yes-man but Bernadotte turned out to be very independent and didn't follow Napoleon's wishes and King Jean focused on building the economy.