The castle was constructed during the 8th and 9th centuries, during the period of Muslim Iberia, as the central place in territory that was primarily agricultural, and necessary to protect its population.
In 1031, after the loss of Córdoba to the Almoravid dynasty, the king of Badajoz opted to transfer to Alfonso VI of León and Castile a few territories on the Iberian peninsula (among them Sintra) in order to gain an alliance with the Christian king. This transfer did not result in any security, and the castle was lost to the invading Almoravid.
After the conquest of Lisbon in (1147) by forces loyal to Afonso Henriques, the castle surrendered voluntarily to Christian forces. Afonso Henriques entrusted the castle's security to 30 inhabitants, granting them privileges in the foral ('charter') signed by the monarch in 1154. The charter suggested that settlers should occupy and inhabit the castle, as a mechanism for guaranteeing the region's security and development.
During the second half of the 12th century, the chapel constructed within the walls of the castle became the parish seat. This was followed by remodelling and construction under the initiative of King Sancho I of Portugal.
In 1375 King Ferdinand I of Portugal, under the counsel of João Annes de Almada, ordered the rebuilding of the castle. While the structure was well fortified by 1383, its military importance was progressively diminishing as, more and more, the inhabitants abandoned the castle for the old village of Sintra.
While the chapel was still being used as a centre of religious activities at the beginning of the 15th century, by 1493 this chapel was abandoned and later used by the small Jewish community of the parish. This was followed in the 16th century by the transfer of the ecclesiastical parish of São Pedro from the castle to the new parochial church in the village. The Jews occupying and using structures in the castle were expelled by Manuel I of Portugal, and the castle was abandoned.