A federal judge in Washington ruled yesterday that D.C. inmates housed in Virginia's prisons cannot yet be forced to cut their hair and shave their beards under a grooming policy that was to take effect today.

U.S. District Judge Henry H. Kennedy Jr. issued a temporary restraining order that blocks prison officials from enforcing the policy against any D.C. inmate who raises religious objections. A total of 1,300 prisoners from the District are being held in Virginia under a contract with the D.C. government.

But the policy will take effect for the overwhelming majority of the state's 32,000 prison inmates, who had until today to comply or face sanctions such as solitary confinement. Kennedy's order covered only the D.C. contingent. Virginia officials contend that beards and long hair, including braids, cornrows and ponytails, give prisoners places to hide drugs and weapons and maintain that some grooming habits also can pose health hazards.

Virginia prison officials said they had not seen the court order but would review it once it arrived. Kennedy's order requires that copies be posted in prisons so all employees can see his instructions.

The Virginia attorney general's office said prison officials have prevailed in four other legal challenges to the prison grooming policy, all of which were filed by inmates from Virginia. Federal judges in Alexandria and Roanoke have refused to issue temporary restraining orders in those cases.

In Alexandria, U.S. District Judge Claude M. Hilton yesterday rejected a request for a temporary restraining order from eight inmates at Lunenberg Correctional Center in Victoria, Va. The inmates argued gender bias because the grooming policy allows women to wear ponytails and shoulder-length hair while men must cut their hair above shirt collars and around ears.

Four D.C. prisoners filed their suit last Friday in U.S. District Court in Washington and cited religious convictions, saying their faiths prohibited them from shaving their beards or cutting their hair. The suit covered only D.C. inmates housed in Virginia who have specific religious beliefs. It noted that the District's prison system imposes no such grooming restrictions. Although he did not issue a final ruling, Kennedy appeared sympathetic, saying the inmates seemed to face a "Hobson's choice."

Most of the D.C. inmates housed in Virginia are at a facility known as Sussex II, a new prison in Waverly, near the North Carolina border. The D.C. government moved 1,211 prisoners there as part of its plans to close the Lorton Correctional Complex in southern Fairfax County by 2001. An additional 87 prisoners are at Red Onion State Prison in the far southwestern corner of the state, and two are at Greensville Correctional Center in Jarratt.

The D.C. lawsuit contended that Virginia's policy violates tenets held by Muslims and Rastafarians. One plaintiff, Isadore Gartrell, shaved under duress, the suit said, "thus shaming himself and sinning against Allah."

The suit was filed against the D.C. Department of Corrections, which has ultimate responsibility for prisoners serving time for D.C. offenses. Virginia prison officials were not named in the suit. D.C. government attorneys contended that no emergency action by Kennedy was necessary.

Kennedy said he wants to hear more arguments on the religious freedom issue at a hearing Jan. 3. In the meantime, he ordered officials to take no action against D.C. prisoners with "sincerely held religious beliefs."

"We believe the judge did the right thing to protect the status quo and protect the prisoners' rights," said E. Desmond Hogan, a pro bono attorney from the Washington firm of Hogan and Hartson. The D.C. chapter of the American Civil Liberties Union assisted the firm in filing the lawsuit.

Kent Willis, director of the ACLU's Virginia chapter, said a challenge in Virginia will be more difficult because the 4th U.S. Circuit Court of Appeals in Richmond upheld a virtually identical grooming policy in a case from South Carolina last year. The federal court in the District is in a different circuit, meaning it was not bound by that precedent.