Why did people get excommunicated in the Middle Ages?
There were other reasons, but these suffice as an example. Often wars were started or diverted by whom the Church supported. Drawing an excommunication upon oneself was to be avoided, especially by rulers, since Christians were not obliged to follow an excommunicated sovereign and thus, if intransigent, a ruler could lose their entire kingdom.