I am surprised at how many things are answered plainly in the scriptures. Here we have the Lord addressing excommunication and its relation to forgiveness.
D&C 64:12 And him that repenteth not of his sins, and confesseth them not, ye shall bring before the church, and do with him as the scripture saith unto you, either by commandment or by revelation.
13 And this ye shall do that God may be glorified—not because ye forgive not, having not compassion, but that ye may be justified in the eyes of the law, that ye may not offend him who is your lawgiver—
14 Verily I say, for this cause ye shall do these things.
This spells out the fact that we exercise church discipline by commandment and revelation. When he says "either by commandment of by revelation" he is saying that if there is a scriptural teaching that spells out the matter than we have a commandment about what to do, but if not then we seek revelation on the matter.
This spells out that the motive for doing it is not that we forgive not, but that we (the church) may be justified in the eyes of the law and may not offend our lawgiver.