(CNN) The man accused of killing a San Francisco woman in what appeared to authorities to be a random shooting has told CNN affiliate KGO-TV that he he did it, but that it was an accident.

"Did you shoot Kate Steinle, the lady who was down at Pier 14?" the station's reporter, Cornell Barnard, asked Juan Francisco Lopez-Sanchez in a jailhouse interview.

"Yes," he answered, according to a transcript of the interview posted on the station's website

But he said the weapon -- which he said he found lying on the ground wrapped in a T-shirt -- went off by accident when he picked it up, according to KGO.

"Then suddenly I heard that boom boom, three times," Lopez-Sanchez said, according to the station's transcript.

Steinle was shot Wednesday while walking with her father on Pier 14, a popular walking spot on the city's waterfront. She died on the way to the hospital.

Kate Steinle died Wednesday after being shot while walking on a San Francisco pier.

Prosecutors have charged Lopez-Sanchez with murder, the San Francisco District Attorney's Office said. His arraignment is set for Tuesday.

The shooting, tragic enough on its own, has inflamed the national debate over immigration reform after it was revealed Lopez-Sanchez is an undocumented immigrant with a felony record who had been deported to Mexico five times

'I want the courts to punish me'

Lopez-Sanchez told KGO he repeatedly returned to the United States after he was deported because he could find work and make more money than in his native Mexico. He said he has worked on ranches in Arizona and helped stock stores in Portland, Oregon. Asked whether he came to San Francisco because there were more opportunities and because officials there would not deport him, he said yes.

He appeared disoriented and it was not clear whether he understood the questions in parts of the interview, which was conducted in English and Spanish. Lopez-Sanchez gave contradictory answers to reporters about what had happened and how he felt . He said he could not recall details of the shooting because he'd taken sleeping medication, but repeated several times that the shooting had been an accident and that the weapon had gone off on its own.

Lopez-Sanchez said he did not have a lawyer and planned to say he was guilty in court.

"I want the courts to punish me as is deserved and for this to end as soon as possible," he said in Spanish.

Suspect was released by city authorities

In March, Lopez-Sanchez was turned over to San Francisco authorities and ultimately released after completing a federal prison sentence.

U.S. Immigrations and Custom Enforcement said San Francisco wanted Lopez-Sanchez on a drug warrant, so the agency handed him over with a request to let it know if he was to be released.

Despite that request, San Francisco authorities let him go in April after the drug charges were dropped.

Freya Horne, chief legal counsel to the San Francisco County Sheriff, said city officials believe such requests violate Fourth Amendment rights against unreasonable searches and seizures.

San Francisco is one of about 70 jurisdictions around the country that have policies limiting police involvement in immigration matters, according to the Immigration Policy Center.

According to CNN affiliate KRON , San Francisco's policy on undocumented immigrants says that police "shall not detain an individual on the basis of a civil immigration detainer after that individual becomes eligible for release from custody."

What role did sanctuary policy play?

Critics of such policies say they allow dangerous criminals to remain living in the United States.

JUST WATCHED Trump: No one wants to talk immigration Replay More Videos ... MUST WATCH Trump: No one wants to talk immigration 00:10

"This woman would be alive today if they did not have this stupid sanctuary law in that crazy city of San Francisco," CNN law enforcement analyst Harry Houck said.

But Ana Maria Salazar, a former deputy secretary of state and policy adviser in the Clinton administration, said such policies don't make for more violence.

"All that data shows that migrants who have documents or who are undocumented who come to the United States have lower crime rates," she said. "You cannot say that it was this policy per se that resulted in the death of this woman."

In a statement Monday, California Attorney General Kamala Harris cautioned against using the case as a springboard for shaping immigration policy.

"A young, innocent woman, Kathryn Steinle, has been killed, and her murderer must be brought to justice. My office stands ready to support the prosecution to ensure he faces swift accountability and consequences," she said. "On the issue of immigration, our policy should not be informed by our collective outrage about one man's conduct."