The people who misled the Galatians in the first century were saying that they needed to be circumcised in order to be justified before God (i.e forgiven for their sins). Paul said he'd like to see those teachers do more than just cut off their foreskin, but go farther and take the whole thing off! Galatians 5:7-12 is the passage where he says this:
"You were running well. Who hindered you from obeying the truth? This persuasion is not from him who calls you. A little leaven leavens the whole lump. I have confidence in the Lord that you will take no other view, and the one who is troubling you will bear the penalty, whoever he is. But if I, brothers, still preach circumcision, why am I still being persecuted? In that case the offense of the cross has been removed. I wish those who unsettle you would emasculate themselves!"
Why would Paul use such harsh language (clearly a form of "cursing") in regard to what the Galatians were being taught? It's because the stakes were so high--namely, the eternal fate and spiritual success of those who were being misled. (See this post for another example of such cursing earlier in the book.)
Martin Luther, in his commentary on the passage, provides some justifications for Paul's use of profanity (and his own, no doubt). First of all, he asserts that Satan himself is behind all such false teaching, and shares the apostle's compassion for poor sinners in need of forgiveness and hope...
The devil is a cunning persuader. He knows how to enlarge the smallest sin into a mountain until we think we have committed the worst crime ever committed on earth. Such stricken consciences must be comforted and set straight as Paul corrected the Galatians by showing them that their opinion is not of Christ because it runs counter to the Gospel, which describes Christ as a meek and merciful Savior.
Satan will circumvent the Gospel and explain Christ in this his own diabolical way: "Indeed Christ is meek, gentle, and merciful, but only to those who are holy and righteous. If you are a sinner you stand no chance. Did not Christ say that unbelievers are already damned? And did not Christ perform many good deeds, and suffer many evils patiently, bidding us to follow His example? You do not mean to say that your life is in accord with Christ's precepts or example? You are a sinner. You are no good at all."
Satan is to be answered in this way: The Scriptures present Christ in a twofold aspect. First, as a gift. "He of God is made unto us wisdom, and righteousness, and sanctification and redemption." (I Cor. 1:30.) Hence my many and grievous sins are nullified if I believe in Him. Secondly, the Scriptures present Christ for our example. As an exemplar He is to be placed before me only at certain times. In times of joy and gladness that l may have Him as a mirror to reflect upon my shortcomings. But in the day of trouble I will have Christ only as a gift. I will not listen to anything else, except that Christ died for my sins.
Second, Paul and Luther both recognize that the persecution they faced (which would certainly not be mitigated by the language they used:), is a sign that they were angering Satan and thus "on the right track"...
Saint Bernard observed that the Church is in best shape when Satan assaults it on every side by trickery and violence; and in worst shape when it is at peace. In support of his statement he quotes the passage from the song of Hezekiah: "Behold, for peace I had great bitterness." Paul looks with suspicion upon any doctrine that does not provoke antagonism.
Persecution always follows on the heels of the Word of God as the Psalmist experienced. "I believe, therefore have I spoken: I was greatly afflicted." (Ps. 116:10.) The Christians are accused and slandered without mercy. Murderers and thieves receive better treatment than Christians. The world regards true Christians as the worst offenders, for whom no punishment can be too severe. The world hates the Christians with amazing brutality, and without compunction commits them to the most shameful death, congratulating itself that it has rendered God and the cause of peace a distinct service by ridding the world of the undesired presence of these Christians. We are not to let such treatment cause us to falter in our adherence to Christ. As long as we experience such persecutions we know all is well with the Gospel.
And finally, Paul and Luther were so strong in their language because they believed the truth of the Word of God itself was being intentionally twisted and corrupted, and if unchecked that would lead to the destruction of the very foundations of the Christian faith...
This goes to show again how much importance Paul attached to the least points of Christian doctrine, that he dared to curse the false apostles, evidently men of great popularity and influence. What right, then, have we to make little of doctrine? No matter how nonessential a point of doctrine may seem, if slighted it may prove the gradual disintegration of the truths of our salvation.
Let us do everything to advance the glory and authority of God's Word. Every tittle of it is greater than heaven and earth. Christian charity and unity have nothing to do with the Word of God. We are bold to curse and condemn all men who in the least point corrupt the Word of God, "for a little leaven leaveneth the whole lump."
Paul does right to curse these troublers of the Galatians, wishing that they were cut off and rooted out of the Church of God and that their doctrine might perish forever. Such cursing is the gift of the Holy Ghost. Thus Peter cursed Simon the sorcerer, "Thy money perish with thee." Many instances of this holy cursing are recorded in the sacred Scriptures, especially in the Psalms, e.g., "Let death seize upon them, and let them go down quick into hell." (Ps. 55:15.)
Luther's comments about the importance of "the least points of Christian doctrine" might be taken to mean that we should curse other teachers who disagree on more minor matters like the mode and subjects of baptism, the Five Points of Calvinism, and worship styles. And perhaps Luther did go too far in that regard sometimes, like when he condemned the other Reformers for their different views of the elements in the Lord's Supper. But I think we should hear his words in the context of the Galatian heresy, which was about salvation and justification rather than other less important doctrines, and take them as a challenge to not tolerate even the smallest deviation from biblical truth in those areas.
Augustine was a hero of Luther's, and the church father was known to say, "In essentials unity, in non-essentials liberty, and in all things charity." So Paul's cursing (and Luther's), was an attempt to promote unity on the most essential issue of how we can be right with God, and they believed it was charitable (or loving) because they were trying to wake people up to the danger of getting that issue wrong.