A civilian security guard planted a cellphone in the ceiling of a women’s bathroom at an NYPD building in Brooklyn and recorded cops as they used the toilet, law enforcement sources said.

Pedro Rodriguez Sanchez, 34, was arrested on Wednesday.

He recorded multiple videos with his phone inside the NYPD Property Clerk Division ladies’ room at the Erie Basin Pound, sources told The Post.

The bust came after a female officer found the phone, left it and told a sergeant. But when they returned to retrieve it, it was gone.

Sources said Sanchez, who is charged with unlawful surveillance in the second degree, allowed police to search his phone. Investigators allegedly discovered that he deleted the footage but were able to get it back.

“Nothing’s ever really deleted on your phone,” a source said. “The computer-crimes unit can retrieve stuff.”