A federal judge ruled today that the Roman Catholic director of a halfway house exercised his constitutional right to "free exercise of religion" in driving three Salvadorans five miles from a refugee shelter to a bus station last March.

U.S. District Court Judge Hayden Head Jr. issued the pretrial ruling in a case involving Jack Elder, 41, a member of the Sanctuary Movement, a network of 180 U.S. church congregations providing haven for thousands of Central Americans fleeing into the United States.

The ruling came after testimony by several religious leaders that scriptures mandate that they give sanctuary to the homeless and hungry. They said that for three years they have considered it a religious obligation to aid Salvadorans fleeing persecution in their country.

Government lawyers now must show that the public interest in prosecuting Elder for violating the law against transporting aliens overrides his freedom of religion.

Elder's attorney is seeking dismissal of the felony indictment but if Head does not do so, Elder will go on trial in the judge's court next week.

Dismissal would give renewed life to the Sanctuary Movement, buffeted last week by a 71-count federal indictment naming 16 activists as co-conspirators for transporting Salvadoran aliens in the United States.

The indictment came after a seven-month infiltration of the movement by two Immigration and Naturalization Service agents and two informer.

Among those indicted were two Catholic priests, three nuns and the Rev. John Fife, pastor of Southside Presbyterian Church in Tucson, whose congregation in March 1982 became the first to declare its church a public sanctuary.

"The issue here is not sanctuary," an INS spokesman said in Washington today. "The issue here is, did these people violate U.S. law? You can bring in all the motives you want to and whether there is a higher law, but the point is they're in violation of statute."

At a news conference here, Fife said: "We'll probably be more and more public from now on."

"If the government considers the movement a conspiracy, then it's the largest conspiracy in history," Elder said.

The Sanctuary Movement, which claims the support of more than 1,000 congregations, has expressed great disappointment in U.S. support of the Salvadoran government and immigration officials' reluctance to grant political asylum to Salvadorans. Last year, 503 of 13,501 Salvadoran applicants received asylum, according to the INS.

Among those testifying on Elder's behalf today were Catholic Bishop John Fitzpatrick of the diocese of Brownsville, Tex.; the Rev. William Sloane Coffin of the interdenominational Riverside Church in New York City, and the Rev. Donovan Cook, pastor of University Baptist Church in Seattle.

"There's no way in the world this is going to deter the movement," Cook testified. "The beauty of the Sanctuary Movement . . . is there's no head, no heart, no leadership other than the decentralized action of religious people doing what they ought to be."

Coffin, known for his early opposition to the Vietnam war, said, "We would not stand for this if the refugees were Soviets being forcibly repatriated to the Soviet Union, or Poles to Poland."

Head last week ruled irrelevant a dismissal motion by Elder's attorneys, who claimed his actions fell under the realm of the Geneva Convention and international refugee law.

Today, he interrupted the witnesses and ordered Elder to the stand. Elder wept as he recalled visiting a refugee camp in Mexico in 1982.

After this experience, Elder testified, "I became full of fire that has not stopped burning . . . . The last two years [running the halfway house] have been an attempt to make my life concomitant with the faith I've always professed."

In a subsequent incident, Elder was indicted last month for allegedly taking Salvadorans from the Mexican border to his halfway house and then to a bus station.

INS district director Richard Casillas testified today that Elder's defense on religious grounds was "as relevant as trying to justify a bank robbery in order to feed a poor child."

Casillas said that trying to control U.S. borders has become "a nightmarish experience" and that 3 million to 4 million illegals avoid apprehension each year. He termed many asylum requests "frivolous" and usually filed to gain more time in this country.