Look at history. Read things like the law codes of Ugarit, which makes one realize that the Deuteronomic law of the Old Testament was a model of egalitarianism and enlightenment for its Age.
In theory, law are the rules a society comes up with and enforces for the sake of order and prosperity. In reality, the laws tend to be the rules those in power come up with and enforce for the sake of order and prosperity. At various times in history, those in power have figured out that if those not in power have some legal recourse for grievances, they're less likely to violently overthrow those in power.
You'll see very oppressive laws when the guys in charge are badly outnumbered by the oppressed and feel obliged to use draconian methods to keep them under control. Roman slave laws got a lot more restrictive after Spartacus's rebellion.
Or the protagonist is arrested because of a plainly ridiculous, vague, and obtuse law that doesn’t apply to what she actually did.
This happens in the Real World when you have an obsolete law that is no longer relevant, so no one actually enforces it, but it's still on the books. Then it gets used to persecute someone the guy with the lawbook doesn't like... (c.f. various state laws against Sodomy)
At various times in history, those in power have figured out that if those not in power have some legal recourse for grievances, they're less likely to violently overthrow those in power.
Exactly. But we rarely see that; most of the time it's just the powerful abusing the law so outrageously that I'm astonished there's not been a revolt. The people would probably figure they have nothing to lose by fighting, at this point.
This happens in the Real World when you have an obsolete law that is no longer relevant, so no one actually enforces it, but it's still on the books.
Yes, but the key phrase in my complaint is "plainly ridiculous." If the heroine's opponents are going to go to the trouble of applying an outdated law to take up her time, they should be smart enough that they're not selecting something that's self-evidently dumb.
Note that in the real world, taking advantage of an obsolete law doesn't always work out well. Example: A Hudson Valley landowner realized that a bunch of farmers owed him feudal dues -- which were way overdue. (This was after NYState had already passed a law to abolish feudalism. And feudalism had never taken hold in that area.)
The result: the Tin Horn Rebellion, during which farmers and their allies disguised themselves as Indians to fight back against this kind of crap. Indirect results included part of the impetus for forming the Anti-Masonic Party (whose first and only Presidential candidate was a Mason....)
Oh -- and a law was passed against disguising oneself as an Indian. Which was used in New York City (through the 1960s, I think) to arrest gay men who wore makeup.