General Provisions
Nothing is an offence if done by a person who is (or who, due to a genuine mistake of fact - not law - in good faith believes they are) legally bound to do it.
This protects someone who commits what would otherwise be a crime because they were actually required by law to do it, or genuinely and reasonably (though mistakenly) believed they were legally required to - though this defence only works for factual mistakes, not mistakes about what the law itself says.
A police officer who arrests the wrong person after a genuine, reasonable factual mistake (believing them to be a different, actually-wanted suspect) is protected by this exception - they aren't guilty of wrongful confinement, since they believed in good faith they were legally bound to make that arrest.