Until comparatively recent times the sin of heresy was, in many countries, punishable by death.
In England, during the fifteenth and sixteenth centuries, one found guilty of departing from the creed and tenets of the church might be condemned to death by burning.
Thus, the earliest uses of this expression, back in the sixteenth century, referred to the literal punishment of heretics, one would be fetched, or raked over the coals literally unless he speedily reformed his actions and beliefs.
From the use of the expression as a threat, almost at once it became a synonym for the sense in which we use it today, to reprimand severely, to censure caustically.