Excommunication is a medicinal penalty of the Church. Its purpose is not necessarily to obtain justice or satisfaction but is meant to awaken an individual’s conscience to repentance (canon 1312 & 1331). Excommunication can either be imposed by the competent authority (usually a Bishop) through a canonical process or it can be imposed by canon law itself when certain actions take place. This last one is called* latae sententiae* or “automatic” excommunication. Automatic excommunication happens when someone commits an act that is specifically punished in canon law by a penalty of automatic excommunication.
The 1983 Code of Canon Law attaches the penalty of automatic excommunication to the following actions: Apostates, heretics, and schismatics (canon 1364); Desecration of the Eucharist (canon 1367); A person who physically attacks the Pope (canon 1370); A priest who in confession solicits another to violate the 6th commandment (canon 1378); A bishop who consecrates another bishop without Papal Mandate (canon 1382); A priest who violates the seal of the confessional (canon 1388); A person who procures an abortion (canon 1398); Accomplices who were needed to commit an action that has an automatic excommunication penalty (canon 1329)
In order for the penalty to be considered to apply certain conditions must be met (canon 1323). The individual must: be at least 16 years old, know that their action was a violation of Church law, have acted freely without threat of force or grave fear, have the use of reason, and not have acted mistakenly.
Unless the canon reserves removal of the penalty to the Holy See then the local Ordinary can remit the excommunication or he can delegate that authority to the priests of his diocese (which most bishops do in the case of abortion).
By and large automatic excommunications are not known to the public. Unless the individual committed the action in a public manner which would cause the local Ordinary to issue a statement about the automatic excommunication, then the burden is on the offender to confess the sin and seek the removal of the penalty.
An excommunicated person is not to receive the sacraments. However if they do so in violation of the law, the sacraments are valid. An excommunicated person who marries has illicitly but validly received the sacrament. In such circumstances the grace of the sacrament would be of no effect since the person is in a state of mortal sin. In the case of confession the sacrament would be invalid because all mortal sins must be confessed for a valid confession (Catechism #1456) and if the individual withholds their action(s) which incurred automatic excommunication they’d be withholding a mortal sin.
The odds that someone could be automatically excommunicated and not know it is **extremely **unlikely. In order to be under the penalty the individual needs to have known at the time of their actions that their actions were a violation of Church law and have committed the actions intentionally with malice (canon 1321), thus someone who is unsure most likely is not under the penalty. Considering how few actions would lead a layperson to incur automatic excommunication and of those few actions how serious they are, it is doubtful that someone would unknowingly be under the penalty. And, once again, given the seriousness of the actions an individual in good faith would have confessed the sin in confession and the priest would have advised them accordingly.