Montgomery County District Court, where the hearing was held. (Dan Morse)

A Maryland judge on Thursday ordered continued detention for a 17-year-old accused as an adult of raping another student at a Rockville high school earlier this month, saying from the bench that even if the 14-year-old girl in the case had at some point agreed to have sex with the suspect, she also could have withdrawn consent later and been raped.

On Thursday, attorneys for Jose Montano came to Montgomery County District Court to ask Judge James B. Sarsfield to issue a bond for Montano, which could have allowed him to be released pending further court matters. The judge denied bond.

The request opened an exchange between attorneys. Defense attorneys have said the sex acts during the school day March 16 were consensual. Prosecutors told the judge that while Montano and the girl may have agreed a day earlier to meet that morning for sex at Rockville High School, the girl was lured into a trap in which Montano and an 18-year-old defendant — Henry Sanchez Milian — forced her into a bathroom stall and took turns raping her.

Prosecutors cited text messages between the two suspects that they say show Montano plotting with Sanchez Milian on how he would get the girl into the bathroom.

“Once he had her nude, you come in and you’ll threaten her/us with telling the teachers, and so that she would do it,” Assistant State’s Attorney Mary Herdman said, describing text exchanges she said occurred between the suspects. “They talk about the fact that they are going to have sex with her in very vulgar ways.”

“This was clearly a conspiracy between this defendant and the co-defendant to get this victim into that bathroom and rape her and commit other sexual assaults against her,” Herdman added.

Herdman also spoke of possible links to the dangerous criminal gang MS-13.

“We have been shown some photos on both of the defendants’ phones of them flashing MS gang signs. Those are confirmed gang signs,” Herdman said.

Gang detectives are examining the images, she added. “That’s another element of what we have going on in this case,” she said.

In an interview after the hearing, one of Montano’s attorneys, David Wooten, described the gang insinuation as “trash.” He said he has no evidence his client was involved in gangs or has a criminal record.

“This is a terrified young man,” Wooten said. “He is suffering with all of this.”

The case, which erupted in national headlines March 17 and was addressed in a White House press briefing, is playing out amid the debate over illegal immigration. Both suspects had come into the United States unlawfully from Central America last year and enrolled at Rockville High School.

Shortly after Montano’s birth in El Salvador, his mother died, leaving him an orphan, Wooten said. The boy was taken in by an elderly woman and remained with her after her own son, Orlando Montano, eventually left for the United States. When the elderly woman died, Jose Montano traveled to enter the United States and rejoin Orlando Montano in Rockville.

Thursday’s hearing focused on Montano’s bond, meaning limited discussion about what role Sanchez Milian had.

An attorney for Sanchez Milian was in court to observe and later repeated a previous statement that any sex acts between his client and the girl were consensual. “It appears all parties were willing participants in the entire encounter,” said the attorney, Andrew Jezic.

The Thursday hearing suggested the arguments each side is adopting as the case evolves.

Two weeks ago, in obtaining charges against Montano and Sanchez Milian, detectives submitted a statement recounting what the female student said:

She told detectives that she’d been speaking with Montano — whom she said she knew as a friend — in a hallway about 9 a.m. when he asked her for sex and that Milian Sanchez was nearby.

The girl told detectives that she said no to Montano but that he continued asking and pushed her into the bathroom, pulled her into a stall and attacked her, according to the detectives’ description in the filing for an arrest.

Sanchez Milian then entered the stall, and the two teens took turns holding her down and raping her as she repeatedly told them to stop, according to the detectives’ statement filed in court.

Defense attorneys have since asserted that the initial account omitted that the girl and Montano had exchanged text messages a day before the incident in the bathroom, agreeing to have sex in school.

During Thursday’s hearing for Montano, one of his attorneys, Maria Mena, said: “ The day before, she agreed to have sex with our client. They talked about it at length.” Mena said in court that “video was exchanged. Very explicit video. Talking about having the encounter the next day. She agreed. They even said where they were going to meet.”

“Our contention is that this girl lied,” Mena said in court. “This was consensual sex, your honor.”

Prosecutors did not dispute in court that the girl had agreed to have sex with Montano and that of the text messages recovered some might help the prosecution’s case while others might harm it.

But prosecutors were insistent to the judge that whatever agreement may have been made in advance about a sexual encounter, the incident turned into forced acts to which the girl objected.

Montano’s attorneys were asking the judge, Sarsfield, to agree that there was enough new evidence to show a weakened case and warrant Montano’s release from jail for now.

In making his ruling, Sarsfield said that even if there were an agreement on having sex, it didn’t negate the account detectives said the girl gave them initially.

Any plans for sex, Sarsfield said, weren’t “irrevocable.”

“She was forcibly taken into the restroom,” Sarsfield said, citing the detectives’ version of the case, “resisted in there, was pulled from a sink into a stall, where she was sexually assaulted over her resistance and protests by both individuals in a variety of ways.”