I'll allow myself to repeat a bit from my earlier response concerning the history of capitals of Poland in more detail.
In the Middle Ages, especially its early and middle part, many kingdoms, Poland included, did not have capitals in the modern sense of this word, and kings were often travelling throughout their lands, with several cities acting as the major seat of power (sedes regni pricipalis). This said, Gniezno is generally considered a main capital of that era, so to say, due to the fact that the first ruler of Poland accepted by the Western powers has been crowned there, and the city hosted several important political events as well as housed major relics.
The new political system, based on Western ideas, especially the increasing centralization of power and introduction of a new political entity that was the Church was not met without opposition among the local upper classes that treated these developments as a challenge to their local authority. Mieszko I and Boleslaw I managed to placate the nobles by territorial expansion, but during the reign of Mieszko II was not so successful. In 1027 he supported Swabian duke Frederik II against the Emperor Konrad II and although his attack on Saxony was successful, Konrad II managed to ally with Ruthenian prince Yaroslav I and negotiate peace with Istvan I, king of Hungary. Having secured his position, Konrad followed with a retaliatory strike against Mieszko II, successfully capturing Lusatia, while Yaroslav I captured part of Red Ruthenia an several important fortified points on the Volhynia-Sanok line. Military losses of Mieszko II weakened his position, increasing discontent among Polish nobility that begun to rebel against the king, quite possibly not without the help from Bezrprym and Otto, Mieszko's brothers, the latter exiled early during his reign, most likely fearing a palace coup. To makes matters worse for the king, Yaroslav I allied with Mstislav, duke of Chernigov and together managed to dethrone Mieszko II and replace him with Bezprym who, however, was quickly murdered in a coup. Heavily weakened Polish king decided to resort to diplomacy and with Emperor's mediation, he agreed to divide Kingom of Poland between himself, his brother Otto and his nephew Thiedrik. However, Otto died the next year and Thiedrik most likely never managed to get to Poland, allowing Mieszko to regain the throne in 1033, but the power shifts heavily destabilized the country.
When Mieszko II died the next year, position of his son and successor, Kazimierz I, grand-grandson of the first ruler of Poland that adopted Christianity and was recognized by the Holy Roman Emperor, was very precarious. He was unable to accept the crown because of the opposition from the rebelling nobles and the Emperor, while Masovia and Pomerania openly challenged royal rule. The lack of a rightful king and chaos in the country was used by Bohemian prince Bretislav I invaded Poland in 1038, counting on capturing Silesia and Lesser Poland that belonged to Bohemia before. Weakened, divided and uncoordinated Polish forces were unable to resist Bohemian army, allowing the latter to not only capture Silesia but also move into Greater Poland that was additionally ravaged by the popular uprising against the royal power and nobility. Not intending to capture the latter province, Bretislav I decided to plunder it, eventually sacking all major cities in the area, including Gniezno, Poznań, Giecz and Ostrów Lednicki. The destruction, followed by capture of a large number of inhabitants changed the center of the royal and ecclesiastical administration into a quite literal wasteland.
This event could quite spell the end of the sovereign Kingdom of Poland, but both Emperor Konrad III and Ruthenian duke Yaroslav I were not fond of neither the idea of their neighbours getting too much power at Poland's expense or the existence of the large, anarchic territory in their immediate vicinity. Thus, Konrad III helped Kazimierz I to regain the rule (although limited to Greater Poland) in 1039 and recover Silesia and Lesser Poland in 1041, while Yaroslav I assisted Polish king in re-capturing Masovia and Pomerania in 1047. It is largely agreed that Imperial support was in large art brokered by Richeza, mother of Kazimierz I and a noblewoman with great political acumen and significant influence on Imperial court.
So, in 1041 Kazimierz I regained a throne of what remained of his kingdom and was limited to Greater Poland and larger part of Lesser Poland. The former province was utterly destroyed, with principal seats of royal and ecclesiastical power being completely destroyed by popular uprising and the Bohemian invasion. On the other hand, the latter area, although still recovering from the invasion, was in much better shape, and local cities suffered far less, with Sandomierz getting relatively unscathed. Historians suggest that Krakow has been chosen because of its good shape, with the castle, cathedral and fortifications still standing, status of a major trade hub, a functioning bishopric, and a proximity to Czech border making monitoring the main potential threat much easier. In addition, aforementioned mother of Kazimierz I and wife of Mieszko II was often residing in Kraków and thanks to a direct patronage, greatly contributed to the city development.
Thus, in 1041, Kraków was essentially the only city fit to be a seat of royal power within the territory loyal to the king.Status of cities in Greater Poland did not improve much throughout the reign of Kazimierz I, Boleslaw II and Boleslaw III, as according to the anonymous chronicle Gesta principum Polonorum written around 1115, the second of the aforementioned kings was granting to his son 'the capital cities of the kingdom, that is, Wrocław, Kraków and Sandomierz'. These three cities correspond to the seats of power in the Duchy of Poland (comprised of Greater and Lesser Poland), Duchy of Sandomierz and Duchy of Silesia. When the son of the Kazimierz I, Wladyslaw I gained power after his brother was forced to leave the country in 1079, he moved the royal seat of power to Płock as this was a city he was residing in (quite possibly for some time, as the local representative of his brother in Masovia).
The city also acted in this capacity during the reign of Boleslaw III who, by dividing the Polish territory between the successors, began the period of provincial division, established the senioral province spanning through the middle of the Polish kingdom, from its southern border to the Baltic sea. This province, with the capital in Krakow was to be always ruled by the oldest member of the dynasty. In addition, many historians assume that Bolesław III intended the lands of his sons to merge with the senioral province after the death of their ruler, thus leading to reunification of the kingdom of Poland with the capital in Krakow under his last son alive. This special status of the city allowed it to thrive and remain the principal seat of power in Poland until 17th century.So, to sum it up, transition of principal seat of power in Poland from Gniezno to Krakow was caused primarily by the large extent of damage incurred by the popular uprising and invasion of Bretislav I in 1038, after which the cities never returned to their former rank (although Poznań eventually recovered and remained an important city in the region). Quick development of Krakow by Richeza and Wladyslaw I made it attractive for the subsequent rulers who, with some exceptions, referred to reside there until actual relocation of the royal court to Warsaw in 17th century.