The area was part of the Great Moravian Empire in the Early Middle Ages, and became part of the emerging Polish state in the 10th century under its first ruler Mieszko I of Poland. During the times of the fragmentation of Poland it was part of the duchies of Silesia, Legnica, Jawor and Świdnica. In the early 13th century, Polish Duke Henry the Bearded erected a defensive castle at the site, due to its proximity to the Polish–Czech border. The settlement was mentioned in documents from 1232 (as "Landeshut") and 1249 (as "Landishute" and "Landishute forensis auch Camena Gora"). In 1254 the Piast Duke Bolesław II the Bald of Legnica gave the area to the Benedictine monastery of Opatovice (in eastern Bohemia), who already had established Grüssau Abbey at nearby Krzeszów. When the abbey passed to the Cistercians in 1289, Landeshut was acquired by Duke Bolko I the Strict of Świdnica, who extended it as a stronghold against the nearby Kingdom of Bohemia and granted town rights in 1292. It received new privileges from Duke Bolko II the Small in 1334. Nevertheless, the duchy fell to the Bohemian crown with Bolko's death in 1368. It burnt down during the 1426 Hussite campaign to Silesia and in the 1460s it passed to the Kingdom of Hungary, before in 1490 it fell back to Bohemia, then under the rule of Vladislaus II, who erected new town walls.