In 1165, the territory of that would become Castelo Branco was conquered from the Moors and donated to the Knights Templar, who at the time dominated Vila Franca da Cardosa. But, by 1198, King Sancho revised the donation so that half the lands of Castelo Branco were placed within the control of Fernando Sanches. Following the model of Ávila/Évora, in 1213 a foral (charter) was issued in 1213. By the following year Cardosa was bequeathed to the Order of the Templo, confirmed in a papal bull issued by Innocence III (in 1245) where, for the first time, the name of Castelo Branco appeared.
The first fortification wall was constructed by the Knights Templar between 1214 and 1230, thereby extending their defensive line with Tomar, Monsanto, Zêzere, Almourol and Pombal. Sometime in the last year, D. Simãeo Mendes, Master of the Knights Templar, ordered the construction of a palace for his knights commanders.
By the end of the 13th century, during the reign of King Denis the castle included four gates: the Golden Gate, the Gate of Santiago, the Traitors' Gate and the Pelame Gate. In the middle of that century a second curtain of walls was constructed that resulted in the existence of seven gates, rather than the three primitive structures. Sometime during this period construction on the keep tower, that was addorsed to the wall was executed, supported from taxes on cereal grains, wine, meat, hospital leftovers, bottles and residual funds from public wills to approximately 600 pounds.
The first reference to the castle's alcalde occurred in a donation letter dated 1 October 1357, when Martim Lourenço de Figueiredo was referenced as the responsible for the defensive structure. By 1408 description of the castle included details of three chambers, a tower and two horse stables (with its own kitchen), a cattle shed, barn and guardhouse (to guard the silver). In 1422 a barbican was constructed.
In the 1422 Rol dos Besteiros there is a reference to 6390 inhabitants, but by 1496 "Inquiries", there were just 839 people within its walls.