Milan was the largest city in Europe and the most economically advanced. Since about 1057 the lower classes in Milan had demanded an improvement in the corrupt and licentious clergy of the city. Street gangs would harass clergymen they suspected of living with women or had acquired their office through the payment of bribes. Rioting became increasingly intense, and the rebels calling themselves the Pataria began to organise under the leadership of a member of the city nobility called Erlembald.
Erlembald received support from the papacy, and even received a papal banner in his fight with the archbishop. This archbishop, Wido who had been captured by the Pataria resigned in 1070, handing over the reigns of the archbishopric to his deputy, Godfrey. Godfrey travelled to the imperial court for his investiture, as had been the tradition with archbishops of Milan for centuries. Whilst Godfrey received ring and staff from King (future emperor) Henry IV (1056-1105), the Pataria raised one of their own, Atto to be archbishop. Atto was recognised by the pope and civil war in the city ensued.
In one of his last acts, pope Alexander II (1061-1073) put pressure on Henry IV by excommunicating his advisors. That excommunication lingered without much effect whilst the situation in Milan changed in favour of the imperial side. The Pataria suffered the loss of its leader, Erlembald in the fighting and after the city had burned down, the imperial party took control. They asked Henry IV for a new archbishop. Henry IV appointed Tedald, one of the members of his chancery to be archbishop of Milan.
This is where the new pope Gregory VII loses it. In December 1075 he writes a letter to Henry IV admonishing him for his decisions in Milan as well as for retaining his advisors who had been excommunicated 2 years before. He threatens to excommunicate the the king unless he reverses his decisions.
More on this story in Episode 32 of the History of the Germans Podcast available here and on Apple, Spotify as well as any other podcasting platform (link: https://history-of-the-germans.captivate.fm/listen)