In his famous essay "Civil Disobedience," Henry David Thoreau argues that people are accountable to their consciences first and their governments afterwards. According to Thoreau, the best forms of government perform the least amounts of governing and relegate ethical decision-making to the populace. Although he states that ideally free-thinking and morally-minded people should not need governments, he qualifies this by stating that "I ask for, not at once no government, but at once a better government."
Thoreau's view is that only when citizens obey the dictates of their consciences, even when these are opposed to laws of the land, will governments become better. However, most people blindly serve the government with their bodies or their minds and give no thought to the ethics of what they are doing.
A very few, as heroes, patriots, martyrs, reformers in the great sense, and men, serve the state with their consciences also, and so necessarily resist it for the most part; and they are commonly treated by it as enemies.
The specific grievances against the then-standing government that Thoreau delineates in this essay are the US invasion of Mexico and the legality of slavery. Thoreau fervently opposed both of these issues, and as a result, as he describes later in the essay, he was put in jail for refusing to pay taxes supporting these enterprises. He declares:
Under a government that imprisons any unjustly, the true place for a just man is also a prison.
Now we can come back to the quote in the question. It has to do with what a just man's reaction should be to unjust governmental policies. Thoreau compares the government to a machine and stresses the importance of stopping the machine if it is doing more harm than good. To put the quote in context:
If the injustice is part of the necessary friction of the machine of government, let it go, let it go; perchance it will wear smooth,—certainly the machine will wear out. If the injustice has a spring, or a pulley, or a rope, or a crank, exclusively for itself, then perhaps you may consider whether the remedy will not be worse than the evil; but if it is of such a nature that it requires you to be the agent of injustice to another, then, I say, break the law. Let your life be a counter friction to stop the machine.
Here Thoreau offers various reactions to government injustices. If the injustice is inherent in the running of government, leave it alone to wear itself out. It is also important to weigh the consequences of your actions. However, if in obeying the government you are harming others, then your duty is to disobey unjust laws. This applies counter friction that works against the governmental machine. In your civil disobedience, you stop the metaphorical machine, which is the government, from doing damage to your fellow citizens.