Unlike some other faiths, it was always known in Christianity that Pope is not "mouthpiece of God", and thus can err.
Actually, modern Catholic Church insists on Pope's infallibility as a part of doctrine.
Admittedly, it's all a part of larger discussion about Papal supremacy which modern Papacy is quite content to keep on the down low, because (at least for a moment) it is more convenient to let parts of the Church larger degree of autonomy.
As opposed to medieval papacy that grasped at power to a ludicrous decree, turning anything into a pretext to claim even more authority.
Yet when he excommunicated Henry first time around, Henry was forced by his nobles to take a walk (to Canossa).
Previously, on Holy Roman Empire:
Henry engaged in attempts to centralize the realm and strengthen his power at the expense of Imperial Princes. As often happened to his successors, he let initial success go to his head and overreached, resulting in negative reaction by Imperial Princes and excommunication by the Pope.
However, when Henry was excommunicated, his nobles did
not force him to take a walk. Instead, Henry spent almost a year gallivanting around and embarrassing himself - until his inability to contain Saxonians became clear. Not to be too harsh on Henry, that struggle continued on and off well into another century, so he wasn't the only one who got stuck in that pile of crap.
Then and only then did the Princes experience a surge in Christian feeling and decided to pressure Henry into reconciling with the Pope. They gathered in a meeting to discuss Henry's behavior as King. In a surprising turn of events, their first complaint was
Henry's ungodly posture towards the Holy Father and overall un-Christian....
I know, I'm hilarious. Of course it wasn't. Their first complaint was that Henry hadn't involved them into Imperial governance. Aka tried to centralize the realm and stop Princes from running around like sword-armed monkeys in a madhouse. Then there was a negotiation, one which Henry wisely led at a head of his army mustered in Oppenheim. And then there was a walk to Canossa as a part of overall agreement between Henry and Imperial Princes, because the Princes benefited from cutting Henry down a notch. It secured their position - or at least that was the plan.
But Henry adapted, made concessions to certain noble parties and went for Round Two.
In short, it was never about whether Henry's excommunication was just or not. It was all, from beginning to the end, about power and politics. Imperial nobility's supposed feelings on whether Pope's treatment of Henry was just or not were too dependent on their own ability to benefit from siding with either Henry or the Pope for it to be a matter of justice.