That year, Mr. Corley was in a visiting room with his wife when Simon Prindle, a New York State corrections officer, ordered him to leave the room and stand against a wall with his legs spread because he wanted to make sure Mr. Corley did not have an erection, according to the complaint.

Officer Prindle, the complaint says, then “paused to fondle and squeeze Mr. Corley’s penis,” and threatened Mr. Corley when he objected. Mr. Corley had nightmares after the episode, and filed a grievance, but did not get anywhere with it, according to the complaint.

Four days later, the complaint says, Officer Prindle stopped Mr. Crawford as he left the prison’s dining hall after lunch. While searching him, Officer Prindle “grabbed” Mr. Crawford’s penis, asking “What’s that?” According to the complaint, Mr. Crawford said: “That’s my penis, man. What the hell are you doing?” Officer Prindle continued to press Mr. Crawford against the wall, “squeezed and roamed” with his hands around the inmate’s genitals, and threatened to send him to solitary confinement if he resisted. Mr. Crawford subsequently went to a therapist to report the episode and seek treatment.

Inmates at the prison filed more than 20 grievances against Officer Prindle, saying that he had sexually abused or harassed them by, among other things, directing prisoners to bend over and spread their buttocks for a proper anal-cavity search, said Zachary Margulis-Ohnuma and Adam D. Perlmutter, lawyers for Mr. Corley and Mr. Crawford.

In 2014, Norman A. Mordue, a federal judge in the Northern District of New York, dismissed the men’s case. He cited a 1997 Second Circuit opinion, Boddie v. Schnieder, as establishing the standard for the sexual abuse that must occur for prisoners to claim a violation of their Eighth Amendment rights.