The castle represents the dominant part of the old settlement. Originally a much smaller medieval building owned by the Counts of Gorica, it was inherited by the Habsburgs, who bequeathed it to the Counts of Cobenzel. With the exception of a brief Venetian rule and the ownership by the Coronini family from Kromberk, the Cobenzel family continued in Štanjel until 1810, when the family eventually died out. From that moment on, the castle was owned by various families.
According to dates inscribed on numerous commemorative plaques, we can assume that the Counts of Cobenzel began the renovation of the castle in 1583, and gave it its present Baroque-Renaissance appearance in 1661. Eight years later, the two-winged residence was completed with a walled enclosure and a monumental Renaissance gateway.
In World War I, the Austrian Army used the castle as a military hospital for its officers. In the interwar period the castle became the central point of public and social life thanks to Max Fabiani. Here was the municipality, school, library and medical centre. In the summer, dances would take place in the castle courtyard as well as concerts and plays. In World War II it was severely damaged during an attack by the National Liberation Army. Renovation began in the second half of the 20th century.