Sometimes it's not just okay to break the law; it's actually essential. There are certain circumstances where laws need to be broken in order to ensure that justice is realized.
An obvious example from American history would be the actions of the civil rights movement. Civil rights campaigners like Dr. Martin Luther King Jr. routinely broke racist laws, as this was the only way they could get them changed. The entire structure of Southern society was so steeped in racism and white supremacy that there was no other way that unjust laws that discriminated against African Americans could be challenged.
Critics of King's approach argued that the civil rights movement should use exclusively legal means to secure the end of racial injustice. But as King and his defenders would always point out, the very legal system itself was riven from top to bottom with racism and white supremacy, and so relying on the law to end the scandal of racial oppression was never a live option.
Whether or not it is ever right to break the law is not a decision that can be reached in advance. It is not an abstract question, but a practical one. The specific facts on the ground will determine whether or not it is right to break the law.
Generally speaking, it is best for society as a whole if everyone adheres to the law. However, in cases where it is impossible to change the law through normal democratic means, as it was in the Deep South in mid-twentieth century America, then it is not just okay to break the law; it is a moral imperative to do so.