HOUSTON -- The man accused of shooting and killing a suburban Houston officer has a history of mental illness and once lived in a homeless shelter, authorities said Monday.

Harris County Sheriff's Deputy Darren Goforth was ambushed and shot 15 times, Harris County District Attorney Devon Anderson said in a court hearing for Shannon J. Miles, who is charged with capital murder.

Miles, a 30-year-old Houston resident who said little in court, is being held without bond. His criminal history dates back to 2005 and includes an arrest in Austin in 2012 that led to Miles being sent to a state mental hospital for several months.

Anderson would not comment on a motive, saying investigators were still trying to figure that out. When asked if it might be connected to heightened tensions around the country between law enforcement and civilians, Anderson said, "I have no idea whether it does or not." This weekend, Sheriff Ron Hickman said the attack was "clearly unprovoked," that authorities believe the 47-year-old deputy was targeted because he was in uniform and there is no evidence Goforth knew Miles.

Anthony Osso, one of Miles' two court-appointed attorneys, told The Associated Press that his client intends to plead not guilty. "He had indicated to the investigating officers that he was not involved in the case," Osso said in a telephone interview.

In 2012, the Travis County District Attorney's Office charged Miles with aggravated assault with a deadly weapon after he got into a fight at a homeless shelter over a remote control, prosecutor Joe Frederick said. Miles was found to be mentally incompetent in October 2012 and he was sent to North Texas State Hospital in Vernon, Texas.

"From this case, you could never tell what would happen" in the future, Frederick said, adding prosecutors treated the case as a "very serious offence" and had offered Miles a plea agreement of seven years in prison. Miles was declared mentally competent in February 2013, but the charge was dropped after the victim could not be located, Frederick said.

Jon Evans, Miles' attorney in the Austin case, said medical privacy laws prevent him from offering any details about Miles' mental illness history. But he was told by Miles' mother that her son had a lifelong history of mental illness.

At the time of the case in 2012, Miles "suffered from severe mental illness," Evans said.

Miles also has three convictions for resisting or evading arrest, as well as convictions for disorderly conduct with a firearm, criminal mischief and giving false information to police. Records show he was sentenced to several short stints in jail, anywhere from six to 10 days.

In court Monday, Anderson read the probable cause statement, which said police first received a call at 8:20 p.m. Friday. Responding officers found Goforth's body face-down at the gas station in the Houston suburb of Cypress.

Surveillance video from the gas station showed the 10-year law enforcement veteran had just come out of a convenience store when Miles got out of his red truck, she said. "He runs up behind Deputy Goforth and puts the gun to the back of his head and shoots. Deputy Goforth hits the ground and then he continues to unload his gun, shooting repeatedly into the back of Deputy Goforth," Anderson said.

Shell casings match the .40-calibre Smith and Wesson handgun found at Miles' home, Anderson said. Miles' next court date is Oct. 5.

The killing evoked strong emotions in the area's law enforcement community, with Hickman linking it to heightened tension over the treatment of African-Americans by police. Goforth was white and Miles is black.

The nationwide "Black Lives Matter" movement has sought sweeping reforms of policing. Related protests erupted in Texas recently after Sandra Bland, a black woman, was found dead in a county jail about 50 miles (80 kilometres) northwest of Houston three days after she was arrested on a traffic violation.

"We've heard Black Lives Matter, All Lives Matter. Well, cops' lives matter, too," Hickman said Saturday.

President Barack Obama on Monday said targeting police is completely unacceptable and "an affront to civilized society." Obama spoke with Goforth's wife, Kathleen, conveying his condolences and telling her he will keep highlighting the uncommon bravery of police officers.

Houston Police Lt. Roland De Los Santos, a childhood friend of Goforth's, called the deputy a "simple guy" who was focused on providing for his family, noting that Goforth's wife is a teacher and the couple has a 12-year-old daughter and a 5-year-old son.

Goforth's funeral is scheduled for Friday.

- Associated Press writers Seth Robbins in San Antonio and Alan Scher Zagier in St. Louis contributed to this report.