U.S. Solicitor General Rex E. Lee told the Supreme Court yesterday that federal restrictions barring legal rights organizations from the annual federal charitable campaign are needed to keep the $100 million-plus drive from becoming a free-for-all for "universities, opera guilds and animal welfare groups."

Lee asked the court to overturn a 1984 U.S. Court of Appeals ruling that the Reagan administration had violated constitutional free-speech guarantees and was "patently capricious and unreasonable" when it barred the NAACP Legal Defense and Educational Fund Inc. and several other legal advocacy groups from participation in the Combined Federal Campaign (CFC).

But attorney Charles Stephen Ralston, representing the groups and asking the justices to affirm the lower court, said, "The motive for expelling us was controversy . . . . We are the only category of organization excluded because we focus on a particular cause . . . .

"The fact some people think we shouldn't be in is essentially irrelevant and constitutionally unacceptable reason for rejecting us," Ralston said.

The arguments offered the two sides the opportunity to present their case in what is likely to be the ultimate legal forum for the controversy. Over the past three years, the Reagan administration has tried to limit access to the CFC, which is one of the most powerful fund-raising tools available to charities.

The Office of Personnel Management, which controls participation in the campaign, has fought to exclude legal advocacy groups and the Planned Parenthood Federation of America from the list of service and health and welfare charities permitted to compete for federal employes' contributions.

The NAACP legal defense fund has collected about $1 million in contributions from federal workers in the four years it was allowed to participate.

Planned Parenthood, which filed an "amicus" brief to the case argued yesterday, has collected more than $2 million over the same period in the CFC.

The group's efforts in support of abortion services have made it a prime target of antiabortion activists. OPM Director Donald J. Devine has expressed antipathy for the group and made several unsuccessful efforts to exclude it from the campaign, efforts that Planned Parenthood fears would be renewed if the government is successful in the suit.

Lee contended yesterday that the inclusion of the defense funds "did pose widespread and serious problems" because of some workers' opposition to the groups' aims. OPM officials estimate that the current drive will raise $123.3 million, up from $109 million for the 1983-84 campaign. But Lee argued that "no one can compare what was with what might have been" had OPM's restrictions been upheld.

Last year, Devine scrapped the previous procedure of publishing a brochure containing statements from all the approved participants, and instead delegated to local CFC administrators the right to determine who participated and whether any list of participants would be distributed.

Lee's argument that the president has a right to circumscribe participation to preserve the campaign's overall integrity seemed to strike a chord with Chief Justice Warren E. Burger, who told Ralston, "If . . . the First Amendment applies, I have difficulty seeing how the Socialist Party would be excluded."

Ralston replied that "the Socialist Party is not a charity and . . . would be totally incompatible in a . . . forum devoted to charitable solicitation."

Earlier, in response to a question from Justice Byron R. White about whether the government could exclude groups from the CFC because they were controversial and might disrupt the fund drive, Ralston said that reason was "not only inadequate but unconstitutional."