Q:

In the Catholic Church, is there a punishment for "heresy"?

Things are often referred to as "heretical" in Catholic literature and doctrine. As a lifelong Protestant (Pentecostal), I am very very inexperienced with the way the Catholic Church is run. 
The only knowledge that I have of the proceedings with someone who commits heresy is of things like what took place during the Inquisition, and torture chambers and devices used by the Catholics in the Dark Ages.
My question is, What happens to a Catholic who commits heresy in modern times? 

A:

The 1983 Code of Canon Law says

§1 An apostate from the faith, a heretic or a schismatic incurs a latae sententiae excommunication, without prejudice to the provisions of can. 194 §1 n.2; a cleric, moreover, may be punished with the penalties mentioned in can. 1336 §1, nn.1, 2 and 3.

– CIC (The online translation is slightly different from my hardback book)

A latae sentitiae excommunication means that the person is excommuicated by the very act; no explicit decree of excommunication is necessary.
Canon 1331 §1 lays down what happens to excommunicated persons, and §2 what happens once the excommunication is formally recognised to have occurred:

§1. An excommunicated person is forbidden:

to have any ministerial participation in celebrating the sacrifice of the Eucharist or any other ceremonies of worship whatsoever;
to celebrate the sacraments or sacramentals and to receive the sacraments;
to exercise any ecclesiastical offices, ministries, or functions whatsoever or to place acts of governance.

§2. If the excommunication has been imposed or declared, the offender:

who wishes to act against the prescript of §1, n. 1 must be prevented from doing so, or the liturgical action must be stopped unless a grave cause precludes this;
invalidly places acts of governance which are illicit according to the norm of §1, n. 3;
is forbidden to benefit from privileges previously granted;
cannot acquire validly a dignity, office, or other function in the Church;
does not appropriate the benefits of a dignity, office, any function, or pension, which the offender has in the Church.

Canon 1336 as mentioned above allows an ordained minister to be further constrained by any or all of the following:

a prohibition or an order concerning residence in a certain place or territory;
privation of a power, office, function, right, privilege, faculty, favor, title, or insignia, even merely honorary;
a prohibition against exercising those things listed under n. 2, or a prohibition against exercising them in a certain place or outside a certain place; these prohibitions are never under pain of nullity;

Note that excommunication is not a punishment. It's a recognition that the person is outside the Church, it's a separation. Canon Law shows what the result of that separation is: basically, the heretic is cut off from receiving the benefits of the Church, including its ministries — the one exception to that would be Reconciliation (Penance).

A:

From the Code of Canon Law:

Can. 751 Heresy is the obstinate denial or obstinate doubt after the reception of baptism of some truth which is to be believed by divine and Catholic faith; apostasy is the total repudiation of the Christian faith; schism is the refusal of submission to the Supreme Pontiff or of communion with the members of the Church subject to him.

This defines what heresy, apostasy and schism are. Now, the Church cannot, and could never, enact civil or criminal punishment for anything it describes as a contravention of its own laws. All punishment she is allowed to mete out is canonic in nature. And thus, further on, we have:

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.

So, heresy, apostasy and schism incur a latae sententiae (that is, automatic) excommunication. This makes sense, since the person, by making a choice (αἵρεσις hairesis) to believe something different from what the Church believes, places themself outside of her communion.  Additionally, a priest can suffer other penalties, according to Canon 1336:

Can. 1336 §1. In addition to other penalties which the law may have established, the following are expiatory penalties which can affect an offender either perpetually, for a prescribed time, or for an indeterminate time:
1/ a prohibition or an order concerning residence in a certain place or territory;
2/ privation of a power, office, function, right, privilege, faculty, favor, title, or insignia, even merely honorary;
3/ a prohibition against exercising those things listed under n. 2, or a prohibition against exercising them in a certain place or outside a certain place; these prohibitions are never under pain of nullity;
4/ a penal transfer to another office;
5/ dismissal from the clerical state.
§2. Only those expiatory penalties listed in §1, n. 3 can be latae sententiae.

So a heretic priest can be ordered to be removed from his parish, lose an office, and/or be forbidden from exercising certain activities such as teaching.
However, outside of the merely administrative sanctions the Church can take against a heretic (forbidding them from teaching at a Catholic institution, ordering them to move to a certain place — this last one mostly in case of religious), she does not have any power to constrain them to accept her rulings, and has merely a power of authority.
This was true in the Middle Ages, too: whenever someone was tortured or executed for heresy, it was never by the Church but always by the State — in those days, heresy was often a criminal offense, too. This is true both for Catholic States like Spain and Protestant ones like Prussia and England.
So the Inquisition tried the defendant, and either found them guilty or innocent, and then turned them over to the civil authorities in the former case.

A:

Heresy brings with it automatic excommunication.
From the Code of Canon Law. 

Can. 751 Heresy is the obstinate denial or obstinate doubt after the
  reception of baptism of some truth which is to be believed by divine
  and Catholic faith; apostasy is the total repudiation of the Christian
  faith; schism is the refusal of submission to the Supreme Pontiff or
  of communion with the members of the Church subject to him.  
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.  

From the above, it works out that heresy brings with it an excommunication that is self-inflicted.    

Latae sententiae is a Latin phrase, meaning "sentence (already)
  passed", used in the canon law of the Catholic Church.  A latae
  sententiae penalty is one that follows automatically, by force of the
  law itself, when a law is contravened.   

That means that once heresy is committed any further process is not necessary for the excommunication to be in effect.  At that point, one cannot receive communion, etcetera1.  Whether or not it is declared publicly is up to the ecclesiastical authority. (Per note by @AthanasiusofAlex)
The only way to restore being in communion with the church is through the process(sacrament) of penance and reconciliation.  This will by necessity be undertaken on a case-by-case basis by the ecclesial authority if the heretic sincerely desires to recant and return to the faith community.   

1Detailed penalty

Can. 1331 §1. An excommunicated person is forbidden:
1/ to have any ministerial participation in celebrating the sacrifice of the Eucharist or any other ceremonies of worship whatsoever;
2/ to celebrate the sacraments or sacramentals and to receive the sacraments;
3/ to exercise any ecclesiastical offices, ministries, or functions whatsoever or to place acts of governance.
§2. If the excommunication has been imposed or declared, the offender:
  1/ who wishes to act against the prescript of §1, n. 1 must be prevented from doing so, or the liturgical action must be stopped unless a grave cause precludes this;  
2/ invalidly places acts of governance which are illicit according to
  the norm of §1, n. 3;  
3/ is forbidden to benefit from privileges previously granted;  
4/ cannot acquire validly a dignity, office, or other function in the Church;  
5/ does not appropriate the benefits of a dignity, office, any function, or pension, which the offender has in the Church.  

