(CNN) -- The man charged in the January shooting rampage that killed six people and wounded congresswoman Gabrielle Giffords will remain in mental health treatment, but could be competent to stand trial in the future if he stays on medication, an Arizona federal judge ruled.
After an hours-long hearing Wednesday, U.S. District Judge Larry Burns extended Loughner's detention at a Missouri prison facility for four more months, at which time he will be re-evaluated, according to court sources.
Loughner, 23, could face the death penalty if convicted in the Tucson, Arizona, shooting rampage. He has pleaded not guilty to the charges. Giffords, a Democratic representative from Arizona who was shot in the head, was among 13 people wounded. Among those killed were a federal judge and a child.
Loughner has been diagnosed as schizophrenic and has spent time on suicide watch while in custody and undergoing treatment at the facility. In May, a federal appeals court cleared the way for him to be forcibly medicated, over the objections of Loughner and his attorneys.
Several mental health experts testified during Wednesday's hearing, the court sources said. One of them, psychiatrist Dr. James Ballenger, told CNN affiliate KGUN after the hearing that Loughner is now remorseful for his actions.
"He didn't even know what he'd done," Ballenger said. "But now he's remorseful and that is another example of his regaining what makes us human."
Both the judge and the psychiatrists noted that Loughner was able to sit calmly during the hours-long hearing without any outbursts, court sources said. He was removed from a courtroom in May after an outburst, KGUN said.
"Only in the last few weeks has he been able to sit still," Ballenger said, according to CNN affiliate KVOA. "He sat there not only for five minutes, but for the six or seven hours, so that's one thing that is much better. He wasn't agitated."
Ballenger has not worked with Loughner, but was brought in as an outside expert after reviewing his files.
Loughner's attorneys argue that prosecutors have failed to prove whether it's likely his condition will improve enough to stand trial.
Burns said it's not guaranteed that Loughner will stand trial, as the side effects of his medication could affect his competency.
Prosecutors wrote in court documents that Loughner had expressed "regret for the circumstances that led to his arrest." When he was asked whether he thought about harming himself, he said, "I want to die. Give me the injection. Kill me now," the documents said.
Giffords' recovery has been called remarkable by doctors. She underwent intensive rehabilitation in Tucson and Houston, Texas.
As of earlier this month, her spokesman said she was considering whether to give her first television interview since the shooting. A program featuring an interview with Giffords' husband, Mark Kelly, is set to air November 14, the day before the anticipated release of the couple's joint memoir, co-written by Wall Street Journal columnist Jeffrey Zaslow and titled "Gabby: A Story of Courage and Hope."
In early August, Giffords received a standing ovation when she returned to the House floor for a critical vote on raising the nation's debt ceiling. But except for a few statements from her office, she has remained out of the spotlight and has not spoken to the media.
CNN's Bill Mears contributed to this report.