Historically, American citizens were legally entitled to use reasonable force to resist unlawful arrest. Some states continue to follow this rule, while others don't.
A statute rejecting the traditional rule might say something like this: "You can't use force to resist if you know or should know that you're being arrested by a police officer, regardless of whether the arrest is legal."
A 2012 Georgia case illustrates the traditional rule that it's sometimes okay to resist arrest with force. An officer had been investigating the firing of shots in or around an apartment building. Outside, he saw a young man wearing a hoodie heading for the building. The officer approached and expressed his desire to speak with the youth, who in turn muttered and kept right on his way. The officer quickened his approach; the youngster began to run toward the building. The young man ran up the stairs and eventually tripped. The officer pounced on and "arm-barred" him in order to apply handcuffs. The arrestee struggled to escape, "kicking his legs about and throwing his elbows back and forth."
Georgia's Court of Appeals focused on that fact that the struggle between officer and suspect occurred after the attempted arrest. To the court, the arrest for supposed obstruction had no basis. Because that arrest was unlawful, the young man "was justified in resisting the attempted arrest with all force that was reasonably necessary to do so." (Ewumi v. State, 315 Ga. App. 656 (2012).)
It's critical to note that one can be convicted of resisting arrest even without having committed the crime that was the basis for the arrest.
For example, in New York it's a misdemeanor to intentionally prevent a police officer "from effecting an authorized arrest." (N.Y. Penal Law § 205.30.) In that state, an arrest is "authorized" if the police have probable cause to believe that the suspect has broken the law, even if the suspect actually hasn't. So, whether or not a suspect has broken the law, if the police had probable cause to arrest him and he resisted, he's guilty of a crime. (People v. Laltoo, 801 N.Y.S.2d 591 (2005).)
On the other hand, consider the New York case of young man who fled the police. An officer received word of a burglary in progress; he arrived on scene to notice the young man and two others near a parked car. The officer and his partner approached the men and asked them what was going on; the young man ran away. The cops eventually caught and arrested him. An appeals court noted that the officers didn't have a description of the burglary suspects or even know where, exactly, the crime occurred. They didn't even know whether the tip about the burglary was reliable. The defendant wasn't doing anything other than standing on the street. The court found that the officers had no basis for chasing the young man, meaning he couldn't be guilty of resisting arrest. (In re Manuel D., 796 N.Y.S.2d 345 (2005).)
A Florida court issued a similar ruling in the case of a juvenile who loudly (and with choice language) protested police actions at an apartment complex. The police commanded him to leave the complex, where a rowdy crowd had gathered. The charge was that he resisted arrest by refusing the command. The court held that the youngster was justified in nonviolently resisting because the police didn't have probable cause to arrest him. (J.G.D. v. State, 724 So. 2d 711 (Fla. Dist. Ct. App. 1999).)
If you want to know the state of the law in your jurisdiction, make sure to consult an attorney experienced in criminal justice issues. Such a lawyer should be able to tell you whether and under what circumstances you might have a defense to resisting arrest or related charges.