A federal appeals court ruled Tuesday in favor of a Virginia man who, as a teen, was once ordered by a lower court to be photographed while masturbating in the presence of armed police officers.

That warrant was ostensibly part of an ongoing sexting investigation into the then-teen, Trey Sims, who had exchanged explicit messages with his then-15-year-old girlfriend. Her mother reported the incident to the Manassas City Police Department in January 2014.

Eventually, the detective assigned to the case, David Abbott, obtained a signed warrant to take photographs of Sims' naked body—including "the suspect’s erect penis"—so that he could compare them to Sims' explicit messages.

When this bizarre effort was unsuccessfully attempted, Abbott then obtained a second warrant authorizing police to escort Sims to a hospital for an "erection-inducing injection." This injection ultimately never took place after massive public outcry.

Abbott committed suicide in December 2015 when officers came to arrest him on separate charges relating to pedophilia.

Ultimately, Sims served one year of probation. By early 2016, Sims sued Abbott's estate, alleging violations of the Fourth Amendment, among other accusations.

Lawyers representing the Abbott estate argued that their client was shielded by " qualified immunity ," the notion in American law that generally protects law enforcement officers in gray-area situations from legal liability.

In a 2-1 majority opinion, the 4th US Circuit Court of Appeals found Tuesday that the initial warrant against Sims was an "obvious, unconstitutional violation."

The 4th Circuit ruled that Sims' lawsuit against the estate of the now-deceased officer who had led the sexting investigation, David Abbott, could move forward. "We cannot perceive any circumstance that would justify a police search requiring an individual to masturbate in the presence of others," two of the 4th Circuit judges wrote. "Sexually invasive searches require that the search bear some discernible relationship with safety concerns, suspected hidden contraband, or evidentiary need."

The case will now be sent back down to a federal district court in Alexandria, Virginia.