A U.S. District judge ruled yesterday that the Reagan administration's chief personnel officer acted illegally when he ordered a 6.5 percent reduction in 1982 health benefits in insurance plans offered to federal employes by two unions.

Judge Aubrey E. Robinson Jr. ordered that the Office of Personnel Management enter into contracts with the two unions at the level of benefits that had been agreed upon before OPM ordered two sets of budget cuts, starting last Aug. 21.

The ruling was the second time in a month that OPM director Donald J. Devine has been told by a federal court that he acted illegally when he tried to cut back on federal employe health benefits plans.

While a few unions who offer health plans have challenged OPM cost-cutting directives in court, most government employe insurance carriers reportedly have agreed to the cutback demands and have wrapped up their plans with OPM. The deadline for such agreements was yesterday.

Devine said last night that the ruling would throw the government's health program into "chaos," because other employe groups now might go into court to challenge cutbacks in benefits. He warned that successful court action by other insurance carriers could cost OPM nearly a half billion dollars more for the program than Congress has provided.

"We are determined to appeal this decision as quickly as possible," Devine said. "We are convinced that the court of appeals will find Judge Robinson's decision illogical, improper and will reverse it."

Devine said he found it "incredible that a federal judge should take it upon himself to direct expenditures of this magnitude, with no regard whatsoever for congressionally mandated budget restraints."

He said that Robinson's ruling underscored Attorney General William French Smith's contention Thursday that the courts have overstepped their powers.

"What we decided was we were going to represent our members, and we were going to contest the illegal actions of OPM in all respects," said James R. Rosa, general counsel to the American Federation of Government Employees.

Both AFGE, which is the largest federal union and represents more than 40,000 workers, and the National Federation of Federal Employees, had sued Devine to block the 6.5 percent cutback.

In his two-page written order, Robinson said that OPM was obliged by law to consider what impact its budget reductions would have on health benefits available to federal employes. Robinson noted, however, that the agency's lawyer had conceded in court that "the only factor considered by OPM in ordering the benefits reduction was savings to the government."

In a separate action that was described as a move to keep premium costs down, Devine warned insurance carriers in September that the government would not approve health benefit plans that included abortion coverage except where the woman's life was in danger. But U.S. District Judge Gerhard A. Gesell, acting in a another case brought by AFGE, ruled that Devine could not support his budget claims and appeared instead to be acting on "ideological" grounds.

As a result of that ruling and in an effort to avoid further lawsuits, OPM agreed this week to approve plans from four unions that included broad abortion coverage. The major insurance carriers, however, such as Blue Cross/Blue Shield and Aetna, which cover more than 70 percent of federal subscribers, already had agreed to eliminate their abortion coverage, an OPM spokesman said.

The spokesman acknowledged yesterday that this week OPM also had reached an out-of-court settlement with 59 other health plans that will allow them to provide abortion benefits to their 250,000 subscribers, provided there is no cost to the government.