In ST 1-2.96.4, Thomas Aquinas argues that laws bind the conscience, i.e., obligate, when and only when they conform to the eternal law, particularly insofar as the eternal law is exhibited in the universal principles of practical reason (a.k.a. natural law). To be just, a law must be good as to:
(1) its end: it must be ordered to the common good;
(2) its author: it must not exceed the jurisdiction of the one who imposes it;
(3) its form: it must not place disproportionate burdens on any of the subjects involved.
A law, however, that is unjust in any of these ways does not impose any obligation. That is, a law ceases to have binding force if any of these is true:
(1) it is not ordered to the common good, but merely to the private good of those who impose it;
(2) it exceeds the authority of those who impose it;
(3) it places disproportionate burdens on any of the people in the community.
An act that does any of these things is, says Aquinas, more like an act of violence than like a law; it may share some features of a just law, but it is not a law in precisely the same sense. Thus Aquinas favorably quotes Augustine as saying that it seems that an unjust law is no law at all. The only way in which an unjust law may obligate is indirectly, namely, when it is clear that disobeying it would lead to evils worse than obeying it.
One thing that is often overlooked is that Aquinas considers an argument (3rd objection) that human laws do not obligate because they sometimes bring injury and loss of character on human beings: they oppress the poor and the humble. And Aquinas accepts it, for those cases in which the hurt induced on anyone is unjust. Oppressive laws are perversions of law, usurpations, acts of violence; no one need have conscientious qualms about disobeying them.
It is this line of reasoning that Martin Luther King, Jr. took up in his famous 1963 Letter from Birmingham Jail. There he argues that a nonviolent campaign follows four stages:
(1) collection of facts to determine whether injustice actually exists;
(2) negotiation in order to resolve the matter peacefully;
(3) self-purification, in which there is careful preparation for nonviolent direct action;
(4) direct action through nonviolent means.
A major worry, of course, through all of this is breaking the law. To alleviate this worry, King appeals to Aquinas's argument, and does so, I think, more thoroughly and insightfully than is usually thought. King says, "Any law that degrades human personality is unjust. All segregation statutes are unjust because segregation distorts the soul and damages the personality." This move fits very comfortably with Aquinas's acceptance of the argument in the 3rd Objection, which connects the non-obligatoriness of unjust laws with the moral and physical injury they induce. It's not a bare appeal to Aquinas, as it might seem on a superficial reading; Aquinas is not just thrown out there as an authority or as an example. Rather, it's an insightful and reasonable application of Aquinas's argument, one that shows that the natural law position has strength where it counts.