This question may be suited for /r/Catholicism/ because it has to do with church hierarchy and church independence.
Firstly we should understand that the Pope was the leader of a \ of fiefdoms in the middle of the Italian Peninsula, collectively called "The Papal States/State". In the 1860s and 70s Italian nationalism was a quickly emerging phenomenon, and the Papal States collapsed into the administration of the Kingdom of Piedmont-Sardinia. The Pope lost control over his territories,and the eternal city of Rome. He retreated into St. Peter's Basilica, and the faithful Italians did not opt to kill the pope for control of the Basilica. For 60 years(I believe) the pope reigned in the Basilica, not recongising the sovereignty of Italy and claiming that the former papal lands were under occupation. Until our favourite fascist, Benito Mussolini, finally rectified this in the Lateran treaties granting the Pope sovereignty over the Basilica. As to why, I believe it has to do more with the secular powers of The Pope and church independence.
Recommended Reading
Rome Papal, the Rise and Fall of Papacy by Robert Fleming
The Pinocchio Effect: On Making Italians, 1860-1920 by Suzanne Stewart-Steinburg
or if you want to go bankrupt
The Struggle for Modernity: Nationalism, Futurism, and Fascism(This is also a good book for understanding Fascism if you want to know more about Mussolini) by Emilio Gentile
The Pope and Mussolini: The Secret History of Pius XI and the Rise of Fascism in Europe by David I. Kertzer