Škofja Loka Castle was thoroughly renovated by its new owners, the Ursuline nuns, at the end of the 19th century. They bought the castle in 1890 and, following the plans drawn up by the architect Viljem Treo, spent the next decade and a half carrying out extensive building work. The central tower in the castle courtyard was demolished in 1892 and all three wings of the castle were extended and renovated, as were the chapel and the round tower. The nuns also had the castle connected to the convent in the town by means of a covered stairway. Into this renovated building they then moved their convent school (at different times, a primary school, a secondary school, a teacher’s college and a boarding school) to which they were able to admit 180 girls. At the time, the school was one of the most beautiful and modern schools in the whole of Austria. During the First World War, there was a military hospital at the castle. During the Second World War, the castle was occupied by the Germans, who exiled the Ursuline nuns. After the Liberation, the castle first held a hospital for German prisoners of war and a prison for those Slovenes who had fought against the National Liberation Army. During the period 1948-1958, there was an ordinary prison within the castle walls. The Škofja Loka municipality took over the management of the castle in 1959 and housed a museum in it.