The city states were de facto independent since the Peace of Constance in 1183, but were still nominally part of the Empire after that. When I check maps they seem to be represented as part of the Empire until 1648, which is when the Treaties of Westphalia were signed, yet I can’t find anything making them de jure independent. What part of the treaty made it so?
For example:
You won't find any mention of it in the Peace of Westphalia because Italy didn't gain independence until 1801! You have to be careful with maps of old empires in general but especially the HRE as it depends on what the cartographer wanted to focus on, what level of administration of the Empire is being depicted and are just as often wrong and oversimplified.
So first to start, it's better to reframe the various states of the Kingdom of Italy not gaining independence from the Empire since the 12th century but gaining autonomy within the Empire.
The Emperors remained active as their capacity as Kings of Italy all the way till 1801's treaty of Lunéville which formally dissolved the Kingdom of Italy. The Italian states had gained autonomy over the centuries to govern themselves but the Emperor still had rights to send representatives, create fiefs and entitle nobility, and often establish garrisons of imperial troops to maintain peace (to various success.)
Imperial Italy comes to an end with a series of peace agreements between Revolutionary France and the HRE & the Habsburgs in their capacity of Archdukes of Austria.
The first peace was the Peace of Leoben in april of 1797 during the War of the first coalition. It was an armistice between Napoleon and the HRE/Austrian commanders in Italy that traded territories in Italy & Netherlands to France along with France supporting Habsburg ambitions in Venice.
The armistice was supposed to usher in an official peace but nothing came of negotiations and the fighting continued.
The second peace was the Treaty of Campo Formio in October 1797which was only between France and Austria, not the HRE but set the stage for the final deal in 1801.
The final treaty of Lunéville formally dissolved the Kingdom of Italy, recognized a number of new Italian republics and French annexations both in Italy and including all the territory west of the Rhine. Although the Habsburgs did receive some other smaller territories as well.
And so with both a bang and a whimper, the Kingdom of Italy established by Karl the Great a millennia before ceased to exist. Although a new Kingdom of Italy would be raised from its ashes soon after Napoleon crowned himself Emperor and King.
But Italy wouldn't be free from Habsburg rule for long, after Napoleon's final defeat. The Kingdom of Lombardy-Venetia in Northern Italy would be born.
Although that's a tale for another day, with answers I don't have.