By Daniel Kelley

PHILADELPHIA, June 16 (Reuters) - A man thought to be the longest-held prisoner in Philadelphia jails without trial was moved to a nursing home on Monday after spending seven years behind bars despite a ruling that he was not fit to stand trial.

"As far as I know, nobody has stayed this long in city jails," said Common Pleas Court Judge Benjamin Lerner, who ordered the transfer of 68-yeaer-old Marvae Dunn.

Dunn suffered a series of strokes shortly after his arrest in April 2007 for shooting his sister-in-law outside of her North Philadelphia home. He was declared incompetent to stand trial in May 2012, according to court records.

At the time, Lerner threatened to hold "those responsible" for his captivity in jail in contempt if Dunn was not transferred to a psychiatric facility, but he remained in jail for two more years.

Lerner said part of the reason Dunn had languished in jail was a reduction in the number of beds in psychiatric facilities. His need for a wheelchair and dialysis made finding a nursing home even more difficult.

"What complicated the situation for Dunn was his physical condition," Lerner said.

Philadelphia's jail system holds more than 8,000 inmates who are awaiting trial or serving sentences of less than two years. Roughly one in five inmates in city jails suffers from diagnosed mental health problems, according to the Bureau of Justice Statistics.

Most of Dunn's incarceration was spent in the jail's medical unit, said defense attorney Bobby Hoof, who took over Dunn's case in March 2013.

"Most of the people in medical ward have emotional issues," Hoof said. "He didn't cause any problems. He was just there, and everybody knew him."

While Dunn likely suffered from mental illness before he was arrested, within weeks of going to jail he suffered a stroke that left him unable to walk or speak, Lerner said.

Lerner said he was not immediately notified of Dunn's condition when the case was sent to his court in December 2012.

"I'm not sure how anyone decided he was competent for a preliminary hearing," Lerner said. (Editing by Barbara Goldberg)