Code of Canon Law
Can. 1364 §1. Without prejudice to the prescript of ⇒ can. 194, §1, n. 2, an apostate from the faith, a heretic, or a schismatic incurs a latae sententiae excommunication; in addition, a cleric can be punished with the penalties mentioned in ⇒ can. 1336, §1, nn. 1, 2, and 3.
§2. If contumacy of long duration or the gravity of scandal demands it, other penalties can be added, including dismissal from the clerical state.
Can. 1369 A person who in a public show or speech, in published writing, or in other uses of the instruments of social communication utters blasphemy, gravely injures good morals, expresses insults, or excites hatred or contempt against religion or the Church is to be punished with a just penalty.
Can. 1371 The following are to be punished with a just penalty:
1/ in addition to the case mentioned in ⇒ can. 1364, §1, a person who teaches a doctrine condemned by the Roman Pontiff or an ecumenical council or who obstinately rejects the doctrine mentioned in ⇒ can. 750, §2 or in ⇒ can. 752 and who does not retract after having been admonished by the Apostolic See or an ordinary;
2/ a person who otherwise does not obey a legitimate precept or prohibition of the Apostolic See, an ordinary, or a superior and who persists in disobedience after a warning.