During the Great Schism there were two men both claiming to be the rightful pope (and eventually, three men). Each pope excommunicated the people who were loyal to a different pope. The schism ended when Martin V was elected in 1417, but he must have been excommunicated by one or more of the popes during the schism.
In retrospect the popes in Rome were regarded as the rightful popes but at the time people were unsure who was the real pope and who was an anti-pope.