Excommunication, the exclusion from a religious community, is most often used by Catholicism, Orthodoxy and Judaism as a punitive measure for political purposes.
Public excommunication was once one of the most dreaded penalties in the mediaeval penal system. Both the Anglican and the Catholic churches derive their present rules on excommunication from mediaeval canon law. Excommunication imposed by a church court or by a bishop in the past could have led to the death penalty or life imprisonment with confiscation of property.
Historical examples of excommunication include Pugachev and Tolstoy being excommunicated from the Russian Orthodox Church, Huss and Bruno excommunicated by the Catholic Church, and Spinoza being excommunicated from Judaism. A recent excommunication in the Roman Catholic Church involved a person in the southern USA who, in the 1960s, publicly opposed the racial integration of church schools.
While there have been a number of excommunications for political, personal or even worse reasons, a religious community needs to capacity to excommunicate in order to care for the person being excommunicated. It is used legitimately when the person being excommunicated is so at odds with the structure of his faith that a continued relationship with the community will result in his spiritual or moral harm. In no case is excommunication used to protect God, the faith or the community.