A Montgomery County judge yesterday ordered the county attorney who represents the police department and is a close adviser to Chief Bernard D. Crooke to testify before a grand jury probing whether police officials allowed high-stakes gambling at the Progress Club in Rockville.

But Circuit Court Judge James S. McAuliffe told Assistant State's Attorney Matt Campbell, who has been presenting evidence to the grand jury since last fall, that county attorney Joann Robertson could not be compelled to answer questions that violate the confidential relationship between an attorney and a client.

Yesterday's hearing was held on motions to quash grand jury subpoenas issued last week to Robertson and Crooke. The hearing provided a rare glimpse into the normally secret business of a grand jury.

During the hearing, Campbell withdrew the subpoena he had issued for Crooke, who had testified voluntarily before the panel for 6 1/2 hours in May. Campbell said in an interview that neither Crooke nor the county attorney are targets of the investigation. However, he left open the possibility that other members of the police department could be implicated in an alleged coverup.

Crooke, who has staunchly denied any wrongdoing, has said in interviews with The Washington Post that the investigation of him and his 800-member department stems from State's Attorney Andrew L. Sonner's personal dislike of him. But Sonner has said that comments made by Progress Club members when Rockville City police raided the club on June 5, 1984, seized more than $25,000 and arrested 21 members, showed that the club thought itself immune from arrest and prosecution for violating gambling laws.

Unlike other criminal laws that allow discretion on the part of police officers, a provision in Maryland gambling laws specifically directs police officers to make arrests when they are aware of such activities.

Charges against individual members were dropped, but the club was prosecuted in a trial last Deember that ended in a hung jury.

The lengthy grand jury probe has focused on three areas:

* Contributions totaling $5,500 for police affiliated charities solicited at Crooke's direction in 1983 from the exclusive, all-male Progress Club.

* Why county police abruptly stopped a years-long undercover investigation of gambling activities at the club in March, 1981.

Whether county police officers assured club members that they were shielded from arrest and prosecution for gambling.

Yesterday McAuliffe, who has a reputation around the Rockville courthouse for patience, berated Campbell for the snail's pace of the probe and what he said were its tangents.

McAuliffe told Campbell that a partial transcript of Crooke's testimony revealed that the prosecutor had asked the police chief questions that relate to events since the grand jury investigation began instead of "what happened before and why."

"There are aspects of the investigation . . . the grand jury needs to assure do not involve steps to cover up an investigation that was and continues to be today lawful," Campbell said. "The question of whether or not the chief of police acted to cover up or impede the investigation is critically important to the people of this county."

But James R. Miller, Crooke's attorney, told McAuliffe he was outraged at the state's treatment of Crooke. "Here is a man who voluntarily exposed himself to the grand jury, who said 'I don't need a subpoena, I'll just walk in the front door.' Not satisfied with that, they (prosecutors) are now saying, 'Ha, ha, I wonder if his lawyer Robertson will back him up,' " Miller said.

"Nobody is suggesting the chief of police of Montgomery County is involved in criminal wrongdoing. Nobody is suggesting the police department of Montgomery County is suspected of a criminal conspiracy," Campbell said. "This is not -- as it has been characterized and not by the State's Attorney's office -- Sonner versus Crooke."

Asked later whether the grand jury is nonetheless probing whether individual officers acted improperly, Campbell replied, "Yes."

McAuliffe later issued a stern warning to attorneys and their clients to stop talking publicly about the Progress Club investigation.

"We're starting from day one now," warned McAuliffe, who oversees the grand jury and extended it seven months ago. "I'm not going to impose a gag order but I'm telling the officers of this court . . . the time to stop talking is now."