Since late antiquity, the Mausoleum of Hadrian had an enormous importance for the control of Rome, given its strategic position along one of the city's main access routes from north.
Due to its height and tower-like shape, it was a privileged observation point, and in 401 AD the emperor Honorius connected it to the Aurelian Walls, making it the most important defensive stronghold on the right bank of the Tiber.
The Mausoleum, still intact, withstood the siege of Alaric's Visigoths in 410 AD, and then that of the Vandals in 455 AD; the barbarians failed to capture it, but they sacked the entire city and even built a village the so called Borgo, near St. Peter's Basilica.
Then came the great siege of 537 AD, when Rome was again attacked by the Goths led by Vitiges, and the Romans barricaded themselves in the Mausoleum under the leadership of General Belisarius. He managed to put them to flight by throwing fragments of ancient sculptures at them, smashed to pieces to use as projectiles.

In the 13th century, the Passetto di Borgo was built, an elevated escape route that directly connected St. Peter's Basilica with the Mausoleum-Castle. At the end of the 14th century, Pope Boniface IX Tomacelli decided to restore what remained of the Mausoleum, by then in ruins, and with the help of the Florentine architect Niccolò di Pietro Lamberti, transformed it into the «most fortified of fortresses». At the end of the 15th century, the Passetto was also strengthened with defensive towers by order of Pope Alexander VI Borgia.
The 16th century marked Rome's period of greatest artistic splendor, and some of the most important artists of the Renaissance were called upon by the pontiffs to decorate the papal apartments that had been built on the upper floors of the Castle.
Pope Leo X Medici called Michelangelo to redesign the Cortile dell'Angelo. Clement VII Medici (1523-1534) called Giovanni da Udine, one of Raphael's best pupils, to decorate the Bagnetto, a small heated bathhouse, with frescoes imitating the recently rediscovered grotesques of the Domus Aurea.
But at the same time, the 16th century marked one of the most tragic events in the history of Rome and Italy: the Sack of the Landsknechts (Sacco dei Lanzichenecchi) in 1552, during which the Castle and the Passetto played a key role.
The Lanzichenecchi were the ferocious German mercenary infantry who descended on the city, commanded by Charles III of Bourbon on behalf of Charles V of Spain.
Thanks to the Passetto escape route, the pope managed to avoid capture and barricaded himself inside Castel Sant'Angelo, where three thousand other people had found refuge; the last fugitives even had themselves hoisted aloft in large baskets.

The siege of the Castle and the sacking of the city lasted seven months, causing inestimable damage. Worthy descendants of the Gothic hordes, the mercenaries burned the city, stole every precious thing from churches and palaces, and destroyed the archives, in a crescendo of brutality and ferocity that resulted in 20,000 deaths. Another 30,000 people died later from the plague brought by the Landsknechts.
After seven months, Pope Clement VII simply had to surrender due to hunger, as food supplies had run out, and resigned himself to paying 400,000 scudi to Charles III of Bourbon «to satiate the greed of his thieves», as a contemporary chronicle reports. Initially, they had demanded 300,000 scudi, but then the ransom price rose.
In April 1536, Pope Paul III Farnese had to humble himself and welcome to Rome as a victor Emperor Charles V of Spain, responsible for the sack. He tried to give the city a dignified appearance, because after nine years signs of devastation and poverty were still visible. The Roman Forum was cleared of two hundred hovels, and a triumphal arch was erected on the corner of Palazzo San Marco; the Aelius Bridge leading to the Castle was decorated with fake stucco statues.
After the Sack of the Landsknechts, all the popes took care to strengthen the Castle's defenses by enlarging or building new walls all around it. Pope Urban VIII Barberini, unfortunately, equipped it with new cannons made from the gilded bronze of the original beams of the Pantheon.
You can read this and much more in Marina De Franceschini's book, «Castel Sant'Angelo. Mausoleum of Hadrian. Architecture and Light», which traces its thousand-year history. Also in English edition.