SAN JOSE — On Monday, Hugo Ernesto Castro walked into the Santa Clara County Main Jail to make a confession. In his hand was a note disclosing the whereabouts of the body of his former girlfriend. A deputy listened to Castro, then told him the case was not in the jail’s jurisdiction.

Miraculously, Castro then followed the deputy’s instructions to walk unaccompanied to San Jose police headquarters, where police arrested him. The jail deputy who turned the confessed murderer out on the street has now been reassigned, sources said, marking another black eye for the already beleaguered jail system.

On his second surrender try, Castro was interviewed by San Jose homicide detectives and directed officers to a downtown condominium where they found the reportedly strangled and stabbed body of 27-year-old Alessandra Barlas. Castro, who has a prior conviction for assaulting another ex-girlfriend in Nevada, was arraigned in a San Jose courtroom Wednesday on one count of murder with a knife enhancement. He is scheduled to return to court Nov. 16.

Responding to an inquiry by this newspaper, the Sheriff’s Office said it has launched an internal investigation into why the deputy failed to detain or otherwise keep Castro close until San Jose officers could take him into custody, which police experts say is routine among police agencies in such instances.

“Once they leave, who knows what’s going to happen next,” said Jim Dudley, a criminal-justice lecturer at San Francisco State University and retired San Francisco police captain. “Maybe they go the two blocks and turn themselves in. Or maybe they have second thoughts, or go home and destroy evidence.”

“You’re not going to spoil someone else’s investigation by making a detention of this guy,” Dudley added. “There’s a huge downside if you let him go and he jumps on the next train out of town.”

According to a statement from Sheriff Laurie Smith, Castro walked into the Main Jail lobby and told a civilian staff member that he wanted to “turn himself in.” After finding no active warrants for him, the staffer spoke with a correctional deputy, who asked Castro what he wanted to turn himself in for, prompting Castro to request a more private conversation, according to the statement.

At one point, Castro reportedly passed the civilian staffer a note stating there was a dead body at an address on Third Street. Eventually, the deputy told Castro to report the body to SJPD.

“If the initial findings are true, then the Custody Deputy failed to meet the expectations of the department and we’ll take appropriate action to deal with the deputy,” Smith said in her statement.

The deputy has been reassigned pending the outcome of the investigation, Smith said.

The snafu comes amid heightened scrutiny on the county jails in the wake of the August fatal beating of mentally ill inmate Michael Tyree, allegedly at the hands of three correctional deputies who have been charged with murder. On Tuesday, the county appointed a blue-ribbon commission led by former San Jose Independent Police Auditor and retired judge LaDoris Cordell to head a top-to-bottom audit and massive reform effort to address voluminous allegations of inmate mistreatment. Internal investigations have already yielded two arrests of deputies for unrelated misconduct.

Meanwhile, the 28-year-old Castro is now being held without bail at the same Main Jail where he initially tried to surrender.

According to a statement of facts written by San Jose homicide Detective Wayne Smith, Castro told police that he and Barlas agreed to meet Friday at a condo at The Globe complex on Third Street. At some point over the weekend, Castro said he strangled Barlas and stabbed her, the statement said.

On Monday morning, Castro went to the jail with the hand-written note disclosing the location of Barlas’ body, and was sent to SJPD, where he gave the same note to officers there. Another set of officers went to the condo and found Barlas on an upstairs bed with several visible stab wounds on her front torso, according to police.

Barlas, a San Jose State University alum, was pronounced dead at the scene. When she was killed was not immediately clear. Neither Castro nor Barlas lived at the condo, police said.

Once Barlas was found, Castro was arrested and interviewed by Smith and Detective Sgt. Rick Yu, during which he told them that he killed her, according to Smith’s statement. Police did not disclose a motive for the killing, the city’s 25th homicide of the year.

Police have said only that Castro and the victim were in a “prior dating relationship,” which friends of Barlas corroborated to this newspaper.

According to Nevada state records, in 2009, Castro was sentenced to three years at a Carson City work camp after a conviction for battery with a deadly weapon against another former girlfriend. Deputy District Attorney David Boyd said that crime would factor into Castro’s sentence if he is convicted in Barlas’ death.

Staff writer Katie Nelson contributed to this report. Contact Robert Salonga at 408-920-5002. Follow him at Twitter.com/robertsalonga.