I'll try explaining it the other way around, with a real-life case. There have been several cases that fit this pattern.
A cop wants to bust a bad guy. That cop gets his wife, a teacher, to pretend to be the DA and tell the bad guy he's authorized to do $crime. Cop busts the bad guy.
In court, bad guy says "the DA said I could ... at least, I thought she was the DA. The real DA replies "I never said a word to the guy. Some teacher said it was authorized, but she has no authority to authorize anything."
In such case, the courts have consistently held that the defendant is not guilty, because they THOUGHT that their actions were authorized and therefore lawful.*
So you see it doesn't matter if the person "authorizing" it is really a cop, a teacher, or a DA. What matters is what the defendant BELIEVES - whether they are trying to commit an act that is criminal or they are trying to aid law enforcement. The legal term is "mens rea", which means "guilty mind",'also known as "criminal intent ".
You are free to think that the courts should have done the opposite and found the person guilty when the "DA" actually isn't a DA. You can think it's wrong or right, but what actually sends people to prison or not in such cases is their actual belief - did they believe their act was authorized or not. The actual identity of the authorizing party does not matter under law.
* This mention of mistaken belief reminds some people of the phrase "ignorance of the law is no excuse". Ignorance of the LAW generally isn't an excuse, but mistake of FACT IS an excuse. "I didn't know poisoning my husband counts as murder" is no good. "The bottle said 'blueberry syrup', so I thought it really was blueberry syrup that I put on his food" is a valid defense. Here we're talking about mistake of fact - the defendant thought the person was (or was not) a proper authority.