Some quotes from Institutes, Book 4, chapter 12: “Of the discipline of the church, and its principal use in censures and excommunication.”
…as the saving doctrine of Christ is the life of the church, so discipline is, as it were, its sinews; for to it it is owing that the members of the body adhere together, each in its own place.
For what will be the result if every one is allowed to do as he pleases? But this must happen if to the preaching of the gospel are not added private admonition, correction, and similar methods of maintaining doctrine, and not allowing it to become lethargic. Discipline, therefore, is a kind of curb to restrain and tame those who war against the doctrine of Christ, or it is a kind of stimulus by which the indifferent are aroused; sometimes, also, it is a kind of fatherly rod, by which those who have made some more grievous lapse are chastised in mercy with the meekness of the spirit of Christ.
[Calvin's opinion on how the excommunicated ought to be treated:] Such as have, therefore, been expelled from the church, it belongs not to us to expunge from the number of the elect, or to despair of, as if they were already lost. We may lawfully judge them aliens from the Church, and so aliens from Christ, but only during the time of their excommunication. If then, also, they give greater evidence of petulance than of humility, still let us commit them to the judgment of the Lord, hoping better of them in future than we see at present, and not ceasing to pray to God for them.

