The postman accused of posing as a cop to lure a 12-year-old girl into his car and later rape her was beaten up in jail despite being in protective custody, his lawyer said in a Bronx courtroom Tuesday.

Carlos Medina, 51, turned himself in for the Jan. 4 incident in which he allegedly raped and sexually abused the pre-teen multiple times over the course of several hours at a motel. Cops say he convinced her to get in his car by flashing a fake badge saying he could help.

Medina’s lawyer, Alexander Sanchez, tried to blame the beating on press coverage from his arraignment last week.

“He got beaten up even though he was in protective custody … He wasn’t beaten very severely but he was attacked,” Sanchez said. But he admitted he didn’t know if inmates had seen his client’s photo.

Still, the judge didn’t allow photography inside the courtroom on Tuesday, saying it would pose a “safety issue.”

Medina, a US Postal worker, was indicted on charges of predatory sexual assault against a child, rape, criminal impersonation and related crimes and faces up to 25 years in prison if convicted on the top charge.

He is due back in court on Feb. 14