A Worcester, Mass., man indicted on firearms charges after he allegedly threatened to kill Secretary of State George P. Shultz and President Reagan will undergo a 30-day competency examination at St. Elizabeths Hospital, a federal magistrate ruled yesterday.

U.S. Magistrate Jean F. Dwyer ordered the examination for Edward Louis Gallo, 41, during a brief hearing yesterday in U.S. District Court in Washington at which a D.C. police officer testified that Gallo had been fired from his job more than a year ago after he refused to seek psychiatric counseling.

Gallo was arrested Tuesday at the Regency Congress Inn on New York Avenue NE after his mother told authorities that her son had left Massachusetts to drive to Washington and that his last words before leaving were "Shultz, you're dead."

James Bradley, who is assigned to the D.C. police department's domestic intelligence unit, testified that officials at the water pollution treatment facility where Gallo worked until 14 months ago had become concerned about his erratic behavior and had told him to seek help.

Bradley also testified that a girlfriend of Gallo's, with whom he sometimes stayed, had reported hearing Gallo shouting at times, and when she questioned him about the shouts, he denied making them. The woman also told authorities that she found unexplained holes in the walls of her residence, which she believed Gallo had made.

Gallo was indicted Thursday on two federal and four D.C. firearms charges stemming from the three recently purchased weapons -- an AR15 semiautomatic rifle, a sawed-off Remington shotgun and a Mossberg shotgun that police said they found in Gallo's car parked outside his motel room.