By Steve Gorman

LOS ANGELES (Reuters) - A San Diego man charged with attacking five homeless men by driving railroad spikes into his victims' heads, killing three of them, was ordered on Tuesday to undergo a psychiatric exam to determine if he is mentally competent, a prosecutor said.

Jon David Guerrero, 39, who is also accused of setting fire to two of his victims, was arrested last month as the lone suspect in a violent crime spree that terrorized the homeless community of California's second-largest city.

Jailed without bond, he is charged with three counts of murder, two counts of attempted murder and two counts of arson.

Guerrero appeared in San Diego County Superior Court for arraignment on Tuesday but entered no plea.

The criminal proceedings were suspended after the defense raised questions about his mental fitness, and the judge ordered Guerrero to submit to an evaluation by a court-appointed panel of doctors, Deputy District Attorney Makenzie Harvey said.

He is to return to court for a review on Oct. 7, she said.

Guerrero lived in a downtown "supportive-housing" project for former homeless men and women and other individuals with special needs before his arrest.

According to Harvey, he was previously convicted of robbery and had been sent to state psychiatric hospital at least once in the past. Records posted with the Superior Court case index show five mental health matters filed under his name since 2008, all of them under seal.

Tuesday's court hearing came as prosecutors disclosed new details of the attacks linked to Guerrero, starting on Jan. 3 with the discovery of the body of a man who had been set on fire. An autopsy revealed one railroad spike lodged in the victim's head and one in his chest, Harvey said.

Four others attacked separately over the next two weeks likewise suffered facial or head wounds from railroad spikes found in their bodies or at the crime scene, she said.

The two surviving victims told police they were attacked as they slept.

Guerrero was stopped on his bicycle and taken into custody on July 15 by police who found three railroad spikes in his backpack, about 90 minutes after the fifth and final victim emerged bleeding and screaming for help at the edge of downtown, authorities said.

All of the victims were homeless men living on the streets or in vacant lots around San Diego, but authorities have not offered a possible motive for the attacks.

(Reporting by Steve Gorman; Editing by Andrew Hay)