Excommunication is a church penalty for a church crime. Usually it involves some sort of abuse of the sacraments by a priest or bishop.
It is rare for a layperson to be excommunicated.
Excommunication is different than mortal sin, although a mortal sin may be part of the underlying church crime. When one commits a serious sin, one must refrain from communion until they receive confession.
With an excommunication, the recipient is forbidden from receiving any sacrament, including confession, until the circumstances surrounding the church crime are corrected. The excommunication must be lifted, by either the local bishop or the Pope, before the penitent can go to confession and resume communion.
Crimes that incur excommunication include a priest attempting to confess his sins to himself, or a bishop ordaining another bishop without the Pope’s permission. Most excommunicable offenses are only applicable to clergy. Impersonating clergy, however, could get a layperson excommunicated. Knowingly getting or helping someone get an abortion could also incur excommunication.