The Oxford Dictionaries says this about
3.1 dated A duty attaching to one's position.
the offices of a nurse
This particular meaning says dated but the word office is relevant because the sergeant in question is a non-commissioned officer; an officer but not formally recognised as such.
But the meaning does suggest another word that could be used, and OD has this to say about
2 (often duties) A task or action that one is required to perform as part of one's job.
You will have sentry duty to perform in the evening and duties throughout the day.
So the sentence you asked about could be
The judge understood that the sergeant could not be found guilty of things that he was obliged to do in the exercise of his duty.