Michael Dreyer, who lives near Seattle, was convicted and sentenced to 18 years in prison in 2012 for possessing and distributing child pornography that police said they found on his computer. On Friday, a federal appeals court overturned his convictions because of the unlikely — and illegal — source of the investigation.

The U.S. Navy. To be specific, an agent of the Naval Criminal Investigative Service in Georgia who had a high-powered software program and used it in 2010 to search computers throughout the state of Washington for evidence of child pornography. When the program picked up two child porn images and a video, the agent contacted the FBI, which tracked down Dreyer’s name and address. The naval office then got in touch with local police, who obtained a search warrant. The Department of Homeland Security later got a federal search warrant, and Dreyer was charged in federal court.

When the search was challenged, the Justice Department said a military investigation was justified because there are military bases in the greater Seattle area, and it’s a crime for members of the armed forces to distribute child pornography. But the Ninth U.S. Circuit Court of Appeals in San Francisco said the computer surveillance didn’t target military bases or personnel but extended across an entire state, resulting in prosecution of someone with no current military connection.

Those actions, the three-judge panel said, violated the Posse Comitatus Act, the 1878 law that prohibits the U.S. military from taking part in civilian law enforcement activities.

Congress has authorized a few exceptions, such as the now-familiar transfer of military equipment to local law enforcement, and the possibility of military assistance to police in emergencies involving weapons of mass destruction. But none of those exceptions covers “direct active involvement in civilian enforcement of the child pornography laws,” the court said. And by a 2-1 vote, the court said the computer search was so extensive, and the government’s arguments in defense of the search were so sweeping, that the incriminating evidence had to be suppressed — a remedy that the law reserves for exceptional cases.

“The government is arguing vehemently that the military may monitor for criminal activity all the computers anywhere in any state with a military base or installation,” Judge Marsha Berzon wrote in the majority opinion. Judging from the evidence in this case, she said, it has become “a routine practice” for the Navy to hack into every civilian computer in a state, search for evidence of child pornography, and turn it over to the police if the computer owner has no relation to the military.

Using the Justice Department’s rationale, Berzon said, naval agents could routinely stop suspected drunken drivers in downtown Seattle “on the off-chance that a driver is a member of the military,” and then give the police department any information it happened to collect on civilians. The department’s claim of such broad authority, Berzon said, shows “a profound lack of regard for the important limitations on the role of the military in our civilian society.”

The liberal Berzon was joined by Judge Andrew Kleinfeld, a conservative with libertarian leanings. Another conservative, Judge Diarmuid O’Scannlain, dissented from the portion of the ruling that overturned Dreyer’s conviction, calling it “a breathtaking assertion of judicial power … for the benefit of a convicted child pornographer.”

Defense lawyer Erik Levin said Dreyer, who remains in prison for now, is in his 60s and has no record of violence. He said the naval office in Georgia has conducted statewide surveillance in other states as well.

“This is, literally, the militarization of the police,” Levin said. “They have enough funding that they can go out and stray from the core mission of national security and get into local law enforcement.”

Here’s a link to the ruling, which contains much more about the Posse Comitatus Act and how it applies: http://cdn.ca9.uscourts.gov/datastore/opinions/2014/09/12/13-30077.pdf.