We know that Count Adolf II of Holstein established the City and See of Lybæk in the 1100s. The City of Lybæk then becomes one of the founding members of the Hanseatic League. During the reformation, the See of Lybæk becomes the Principality of Lybæk. Meanwhile, Sweden conquers several Hanseatic towns, including the City of Lybæk, and forcing them out of the Hansa League. The Principality of Lybæk remains a part of Holstein, which by then was part of the Dano-Norwegian monarchy.
After the Great Nordic War in 1721, Sweden surrenders the City of Lybæk to Denmark-Norway. The city remains a separate state within the Dano-Norwegian monarchy, and joins the Baltic League.
In 1809, Sweden goes into union with Denmark-Norway to form the SR, and the City of Lybæk becomes a member state.
Prussia tries to seize Holstein in 1849 but does not succeed. In 1864, Prussia tries again but only manages to seize the City and the Principality of Lybæk. After GW2, Lybæk is returned to the SR - the Principality becoming a fully integrated part of Holstein, and the City as a separate city state of the SR.