The U.S. Court of Appeals here told the Pentagon yesterday it cannot discharge homosexuals from the military without offering specific reasons in addition to their homosexuality.

The appellate court, noting that some homosexuals are allowed to remain in the military, overturned a lowe court ruling upholding the discharges of Air Force Tech. Sgt. Leonard P. Matlovich and Navy Ensign Vernon E. Berg III, two hmomosexual rights activists.

The military may be able to justify the discharges, the court said, but neither man was given any "reasoned explanation . . . which is intelligible to this court or permits any meaningful judicial review."

The unonimous decision throws the controversial issue of homosexuals serving in the armed forces back to the Defense Department, which only this year changed a long-standing policy so that homosexuals kicked out of the service with less-than-honorable dismissals could apply for honorable discharges.

Neither that Air Force nor Navy had any immediate comment on the ruling, but both Matlovich, 35, and Berg, 27, said they were delighted with the decision. Both men are seeking reinstatement in the service and back pay for the years since their dismissals.

Matlovich, who lives in San Francisco, is seeking appointment to the city's Board of Supervisors to replace Harvey Milk, the homosexual rights activist who was slain last week. The former serviceman said that "like a dictatorship, the Air Force did what it wanted" in cases involving homosexuals. "Now they have to tell homosexuals and the American public their reasons."

Berg, a Naval Academy graduate who now is working on a master's degree at Pratt Institute in Brooklyn, said that "the military has never been confronted about who they keep" in the armed forces. "I've always maintainted that all the services can discharge individuals whose sexual acts interfere with their job performances or who have committed some sexual crime.

"But they should not have the right to discharge someone on the mere existence of a homosexual past," Berg said.

Under both Air Force and Navy policies, homosexuals, when their sexual preferences are known, generally are dismissed from the services. But that policy is discretionary.

"What disturbs us," the appellate court said in the Matlovich case, "is that it is impossible to tell on what grounds the service refused to make an exception or how it distinguished this case from the ones in which homosexuals have been retained."

Both Air Force and Navy spokesmen said yesterday they did not know how many homosexuals have been kept in their services after the service member's homosexuality became known.

The appellate court decision written by Court of Claim Judge Oscar H. Davis and concurred in by Chief Appeals Court Judge J. Skelly Wright and Judge Spottswood W. Robinson III, noted that the Air Force had acknowledged that Matlovich had an "outstanding" service record.

The appeals court said that various Air Force review panels had concluded that Matlovich's outstanding record was not sufficient to allow him to keep his assignment at Langley Air Force Base in Hampton. Va. But several Air Force decisions have "no hint why it would not be appropriate to retain" Matlovich, the ruling said.

"The almost total lack of specificity in the Air Force's determination leads one to consider the possibility, for instance, whether Matlovich's failure of retention may have been affected by his 'going public' with his homosexuality and the publicity surrounding his case, and that if his homosexuality had been discovered and handled by the Air Force, without Public notice the result might have been different," the decision said. Matlovich's discharge hearing was widely covered by the news media in September 1975.

In Berg's case, the Navy Administrative Discharge Board "found that his record in the service did not reflect such an outstanding potential as a naval officer as to militate against separation," the appeals court said.

The appellate court ruled, however, that the Navy's decision on Berg was so imprecise that it could not tell what were the "actual considerations which went into the Navy's ultimate decision not to retain Berg."

Both Matlovich and Berg have remained active in homosexual rights causes since their discharges. Matlovich said he raised money nationwide this year to help defeat Proposition 6 in California, a measure that would have banned homosexual teachers in the California public school system. Berg said his companion, Lawrence Gibson, has recently published a book about his dispute with the Navy entitled "Get Off My Ship." CAPTION: Picture 1, TECH. SGT. LEONARD MATLOVICH . . . seeks San Francisco post; Picture 2, ENSIGN VERNON BERG III . . . working on master's degree