The gun used by a Mexican illegal immigrant when he allegedly shot and killed a 32-year-old woman at a San Francisco pier belonged to a federal agent, a source confirmed to Fox News Tuesday.

It was not immediately clear how Francisco Sanchez, 45, would have obtained the weapon. However, the San Francisco Chronicle reported sources told the paper the gun had been stolen during a car burglary in June.

Earlier Tuesday, Sanchez pleaded not guilty to first-degree murder in last week's shooting of Kathryn Steinle, 32, while she was walking with her father and a family friend at Pier 14. Police said witnesses heard no argument or dispute before the shooting, suggesting it was a random attack.

Sanchez had previously told KGO-TV Sunday in a mix of Spanish and English that he found a gun wrapped inside a shirt while he was sitting on a bench at the pier and smoking a cigarette.

"So I picked it up and ... it started to fire on its own," Sanchez said, adding that he heard three shots go off.

A source familiar with the investigation told the San Francisco Chronicle that Sanchez said he was at the popular pier to shoot at sea lions, and discarded the firearm after realizing he had shot Steinle.

The shooting has drawn national attention and criticism of the city's sanctuary ordinance after federal officials revealed that Sanchez has seven felony convictions and was deported five times to his native Mexico.

U.S. Immigration and Customs Enforcement had turned Sanchez over to authorities in San Francisco on March 26 on an outstanding drug warrant.

The Sheriff's Department released Sanchez on April 15 after the San Francisco district attorney's office declined to prosecute him for what authorities said was a decade-old marijuana possession case.

ICE spokeswoman Virginia Kice said the agency had issued a detainer for Sanchez, requesting notification of his release and asking that he remain in custody until immigration authorities could pick him up. The detainer was not honored, she said.

Freya Horne, counsel for the San Francisco Sheriff's Department, said Friday that federal detention requests are not sufficient to hold someone. Under the city's sanctuary ordinance, people in the country illegally aren't handed over to immigration officials unless there's a warrant for their arrest.

Fox News' Jessica Miller and The Associated Press contributed to this report.