The first references to the castle area mention a tower house built in the southwest corner of the city, beside the fortification walls.

In 1293, the castle became the property of the Visconti family, who had important fortification works built, and the construction was completed with residential buildings under Giovanni Visconti, who had been bishop of the city.

With the death of Filippo Maria Visconti in 1447, control of the duchy passed to Francesco Sforza. Significant work was carried out under Galeazzo Maria Sforza (1466-1476), with the building of the mighty reinforcement walls known as the “Garland”, with four towers at the corners and two gateways. The first was on the south side, while the second led to the city, about halfway along the north side, with a defensive tower, drawbridge and ravelin.

Under the Spanish rule, the city was given an imposing system of fortifications, which were completed in the early 1930s. In 1788, the bastion to the east of the castle was converted into a public pathway and, shortly afterwards, the bulwark of San Giuseppe was made into a garden.

In 1803, the city authorities decided to transfer the public prisons here; in the late 19th century and for much of the 20th century, the castle was the focus of city planning discussions, with a series of projects and new proposals for its use.

On 3 January 1973, it ceased to function as a prison, with the transfer of the inmates to a new location.