Why were civil rights protesters met with violence if they were, in fact, not breaking any rules?
The violence of the Civil Rights era was indicative of the rage of Whites when Blacks attempted to exercise the rights guaranteed them under the constitution. The above answer is correct in noting that Civil Rights activists were in fact breaking the law. However the penalty of the law was a fine or imprisonment, not beatings, police dogs and fire hoses, all of which were used by law enforcement against these people. Thus one is still left to wonder why this happened.
Southern Whites, rightfully or wrongly, had lived for many years in a society in which racial separation was sacrosanct. Those who engaged in civil disobedience to unfair Black Codes threatened the very social structure to which so many whites had grown accustomed. Although to the modern eye Black Codes were manifestly unjust, the White People of the South had grown up believing that racial separation was tantamount to the law of nature. They had learned it from childhood and heard/saw it reinforced in both the classroom and the pulpit. Their response was that of those who saw their very way of life threatened. The response of law enforcement was often brutal and far out of proportion to the offense committed; and in hindsight it appears barbaric. However, as one who as a child observed personally many of these actions, I can tell you that those who engaged in these brutal acts believed they were responding to a threat to the social order, and they intended to crush that threat in the most forceful manner.
I do not mean by this response to justify the cruel actions of many during that time; they are in fact beyond justification. However to truly understand the reaction of Whites, one must understand how those Whites thought.
In many instances, civil rights protestors were, in fact, breaking laws. Many of their actions, including sit-ins, marches, and other instances of direct protest involved civil disobedience of Jim Crow laws passed either at the state or the municipal level. The Freedom Riders, for instance, intentionally defied segregation laws (which had, of course, been ruled unconstitutional at that point) in order to make a political point. At other times, they defied orders of police officers and other officials to cease and desist protests. This happened in the streets of Birmingham and on the bridge at Selma, in particular. When they broke these laws, law enforcement officials used brutal violence to restore "law and order" and end the protests. Whether or not they broke laws, as the question implies, is beside the point. The violence of law enforcement and white mobs in the South speaks to the tenacity with which many southerners sought to maintain white supremacy in the South.