S&M can be criminal even if it’s consensual, a Brooklyn judge said today during the arraignment of a self-described Craigslist sex-slave master.

“We’re dealing with two individuals with varying degrees of mental instabilities,” Judge Patricia DiMango said in the case of accused sicko “master” John Hopkins and his alleged victim, a 27-year-old Wisconsin woman.

“In these types of situations, with the facts presented by both sides, both the consensual and criminal can co-exist,” the judge said.

“At some point, it can change to a situation where no means no. There comes a time when they’re not playful fun any more and they become dangerous — criminally dangerous.”

Still, the judge said, “I’m not denying that at some point and at some time this abuse and torture was consensual.”

The victim says she was raped and held hostage by Hopkins in his Williamsburg apartment for more than a week last month after she answered an ad to live in New York for free in exchange for housekeeping duties.

Hopkins says he and the woman were into sadomasochistic role-playing.

But prosecutors say Hopkins, 45, flogged the woman and kept her chained to a radiator against her will as he slept and left the apartment. Hopkins also called the woman “b—-h” and “slut” and forced her to drink large amounts of water while forbidding her from relieving herself, they said.

“The defendant set up slave rules for [her] to follow,” Assistant District Attorney Christopher Laline said. “Then he punished her if she disobeyed.”

The woman — a sushi chef at a well-known Japanese restaurant — was occasionally freed to work. But other times, she was held captive — even breaking her hand at one point trying to free herself, according to prosecutors.

“This is a heinous crime,” Laline said.

Hopkin’s lawyer, Andrew Stoll said the pair knew each other for two years and had a consensual relationship. He said the relationship only blew up after Hopkins kicked her out of his apartment for heavy drinking.

“It stretches credibility beyond the breaking point to say that from the get-go, she was being held against her will,” Stoll said. “I cannot imagine there will be a conviction here.”

Di Mango today denied an application to release Hopkins on his own recognizance, kept bail at $350,000 and ordered Hopkins not to contact the victim. The case was adjourned until April 19.