Four high-ranking members of the Church of Scientology were held in contempt of court yesterday by a U.S. judge here after they refused to testify as government witnesses in the burglary trial of two other church officials.

One of the four, Mary Sue Hubbard, wife of church founder L. Ron Hubbard, unexpectedly agreed to take the witness stand shortly after U.S. District Judge Aubrey E. Robinson Jr. ruled that Hubbard and three other officials had violated his order to testify in the case. It was not clear yesterday why Hubbard had agreed to testify. Her attorney, Leonard B. Boudin, had told Robinson earlier that Hubbard suffered from various health problems, including hypoglycemia.

Robinson sentenced the other three church members to serve 30 days in jail or pay a $30,000 fine each for their refusal to testify at the trial of Jane Kember and Morris Budlong. Kember and Budlong are accused of nine counts of burglary in connection with a series of break-ins into government offices, including the Justice Department and the Internal Revenue Service, in 1976.

Robinson indicated he would lift the contempt finding against Hubbard after she completes her testimony, which is expected to resume today.

All four church officials held in contempt yesterday and five other high-ranking church members were sentenced to prison terms and fined in December 1979 after they were found guilty by Judge Charles R. Richey of conspiracy to obstruct justice. The government had contended that the church members had engaged in a massive criminal conspiracy to plant spies in government agencies and conduct break-ins. All nine are free on personal bond pending the outcome of appeals. Kember and Budlong were charged along with the other nine members. They were extradited from England to stand trial.

At the outset of this trial, Hubbard and the three other church officials refused to testify as government witnesses, even though they had been granted immunity from prosecution for any statements they might make. Among other reasons, the four asserted that the government's demand for their testimony violated their constitutional protections against self incrimination.

Robinson held all four in contempt and the case went to the U.S. Court of Appeals. The appeals court, in a 31-page unsigned opinion, upheld Robinson's earlier contempt finding. Robinson issued his ruling yesterday after all four church members took the witness stand and again refused his order to testify.