What happens if the Pope is automatically excommunicated? Some actions incur automatic excommunication.  While it is debated whether a Pope can lose the office via heresy, what happens if a pope commits a sin other than heresy, such as abortion or violating the seal of confession, which carries an equal penalty?  Is the Pope subject to the automatic excommunication?  If so, would the election of a new Pope be called for?  What would then happen (in terms of the Papacy) if the excommunicated Pope repented and rejoined the church?
As the article here states (linked in the comments), the short answer is that the current legislation of the Church (i.e. the Canon Law) does not foresee such situation to occur. Perhaps it does not do so because under its own beliefs, God will never allow that to happen.

On the one hand, some excommunications (ferendae sententiae) are not automatic. They require a legal procedure in the form of a judicial investigation. One thing this investigation aims to find out is if all the conditions for an excommunication were met, e.g. that the person knew about the penalties of the sinful action to be conducted. These investigations are carried out by a judge, which is designated by the bishop. Canon Law states:


  Can.  1419 §1. In each diocese and for all cases not expressly excepted by law, the judge of first instance is the diocesan bishop, who can exercise judicial power personally or through others according to the following canons.


The bishop has himself the right to be the judge, and to reserve some cases to himself:


  Can.  1419 §2. The judicial vicar constitutes one tribunal with the bishop but cannot judge cases which the bishop reserves to himself.


Thus, ultimately it is the Pope, as Bishop of Rome, who can decide if he is to judge himself or not, as the matter cannot be delegated to a superior. 

Now, recall that the purpose of excommunication is to make the person reconsider his/her error, and reconcile with God/Church. Thus, these types of excommunications could be quickly irrelevant if the Pope were to repent. All he need to do is to design himself as the judge for his case, and take notice that he repented, following the ordinary legal procedures (upon which he has full authority). Yet, if he were not to repent, it could well be the case that the Pope could block an excommunication process against him, or appoint himself as judge and dictate in favour of himself (e.g. that he was not aware of the penalties), and thus, there would be no excommunication. In other words, even if he committed a sin such a s to deserve excommunication, he might not excommunicate himself. Therefore, nothing will happen. 

On the other hand, if the excommunication were to be automatic (latae sententiae), then, as point 1.3 of Canon 1331 states, an excommunicated person is forbidden:


  to exercise any ecclesiastical offices, ministries, or functions whatsoever or to place acts of governance.


This is the real conundrum. The See of Rome is de facto without a Bishop. More importantly, as explained in this answer, most of dioceses have an adjunct bishop, which takes office if the principal bishop leaves the place (e.g. if he dies). However, precisely because the See of Rome is the primus inter pares, and the see of the Pope, this one does not have an adjunct bishop! In other words, the See of Rome would be sede vacante! This means a new process for electing a pope must take place. 

However, recall again that the excommunicated Pope (so no longer the Pope) can repent, and ask to the corresponding authorities (in order to make the process valid under the Canon Law) for reintroduction into the Church. Only if he is not willing to repent then the election process would go ahead. It would not be the first time in history where one "invalid Pope" claims to be the real Pope. Now, if a new Pope is elected and then the old one decides to ask for repentance, then that would be the ultimate bug in the software. Surely God will spare the Church from that ever occurring!