In America we are already functioning with a kind of anarchy/lawlessness due to selective enforcement of existing law at all levels; from individual officers up to the 'President', from municipal resolutions up to our very Constitution. The ATF is virtually entirely built on laws in direct contradiction to our Constitution. So if an individual officer is given an order (direct or standing) in contradiction to the Constitution, they should decide (individually, if necessary, but hopefully as a force) to ignore/reject that order (unless you believe that "I was just following orders" is a valid legal defense.)
Now, all that has only touched on written law, but virtually everyone is going to agree that there are certain principles which supersede written laws. In a well functioning society, everyone broadly agrees on what these principles are and they either form the basis for the written laws, or the written laws aren't needed because people follow the same core principles. But in a poorly functioning society (virtually every modern western nation) written laws exist as an attempt to enforce some homogeneity, based on (at best) 'compromise' core principles, or (more often) the core principles of the group holding the most power, or (even worse) don't exist at all/aren't enforced and everything is up to the whims of the group with the most power.
So to actually answer your question, at a functional level, society determines which laws are 'unjust', based on its core principles. In America those core principles were codified in our Constitution and other founding documents, along with commentaries from the authors and signatories of those founding documents. Unfortunately, those core principles are no longer held in common by either the government or the people, and thus are regular ignored to implement and enforce unjust laws.
(I could give an argument for inherent/natural/divine law, but from a practical perspective these either exist as the core principles on which a society is founded, or are enforced without any input from society, so I didn't feel it was worth covering when there are so many others which have already covered these concepts in more detail.)
EDIT: Also, as a further post-scriptum, the founders also gave the solution to society disagreeing on core principles, but as yet there doesn't appear to be a willingness to go down that path.
In America we are already functioning with a kind of anarchy/lawlessness due to selective enforcement of existing law at all levels; from individual officers up to the 'President', from municipal resolutions up to our very Constitution. The ATF is virtually entirely built on laws in direct contradiction to our Constitution. So if an individual officer is given an order (direct or standing) in contradiction to the Constitution, they should decide (individually, if necessary, but hopefully as a force) to ignore/reject that order (unless you believe that "I was just following orders" is a valid legal defense.)
Now, all that has only touched on written law, but virtually everyone is going to agree that there are certain principles which supersede written laws. In a well functioning society, everyone broadly agrees on what these principles are and they either form the basis for the written laws, or the written laws aren't needed because people follow the same core principles. But in a poorly functioning society (virtually every modern western nation) written laws exist as an attempt to enforce some homogeneity, based on (at best) 'compromise' core principles, or (more often) the core principles of the group holding the most power, or (even worse) don't exist at all/aren't enforced and everything is up to the whims of the group with the most power.
So to actually answer your question, at a functional level, society determines which laws are 'unjust', based on its core principles. In America those core principles were codified in our Constitution and other founding documents, along with commentaries from the authors and signatories of those founding documents. Unfortunately, those core principles are no longer held in common by either the government or the people, and thus are regular ignored to implement and enforce unjust laws.
(I could give an argument for inherent/natural/divine law, but from a practical perspective these either exist as the core principles on which a society is founded, or are enforced without any input from society, so I didn't feel it was worth covering when there are so many others which have already covered these concepts in more detail.)