In 1929, the fascist government of Italy made several treaties with the Catholic Church's Holy See and the Lateran Treaty, establishing Vatican City as an independent entity. The Lateran Treaty is actually one of three so-called Lateran Accords that dealt with the independent status of the Roman Catholic Church and proved successful enough so that even after the end of the war Italian governments honored the treaties.
Wikipedia explains that the pacts consisted of three documents:
• A political treaty recognizing the full sovereignty of the Holy See in the State of Vatican City, which was thereby established.
• A concordat regulating the position of the Catholic Church and the Catholic religion in the Italian state.
• A financial convention agreed on as a definitive settlement of the claims of the Holy See following the losses of its territories and property.
The talks that culminated in the Accords actually began in 1926 and were signed, when completed, by Benito Mussolini, Prime Minister of Italy among others. The Accords were signed at Italy's Lateran Palace. The Lateran Treaty in particular made it clear that the Catholic Holy See would not in any way be part of Italy or the Italian government. The Catholic religion was also officially made Italy's state religion. Claims by the Church against Italy for confiscation of property were dealt with as well.
After the signing, Mussolini had Italy pay for certain improvements to the grounds of Vatican State. After the war, the Lateran Accords became part of the Italian Constitution. In 1984, the clause making Catholicism Italy's state religion was struck. Also, payments made to the Church were replaced by an income tax levy on Italian citizens. The Vatican does not today immediately adopt all laws as passed by the Italian parliament and continues to function as the independent state that it is.