Mayor Marion Barry's spokesman said yesterday that the White House acted unfairly and perhaps illegally last week when it reomoved a Carter appointee from the city's Judicial Nomination Commission four years before his term expired and replaced him with an appointee of its own.

The White House announced Saturday that it had appointed Philip Lacovara, a former high-ranking member of the Watergate prosecution staff and now a lawyer in private practice, to replace William A. Borders, appointed last year to a five-year term on the commission that nominates persons for membership on the D.C. Superior Court and Court of Appeals.

It marked the first time in the six-year history of the commission that a president had effectively bumped a commission member to make way for his own appointee.

Borders, who is president of the National Bar Association and worked as a national fund-raiser for Carter during the last presidential campaign, said that he still considers himeself a commission member and intends to file suit shortly to block Lacovara from taking his seat.

The mayor's press secretary, Alan F. Grip, said yesterday that Barry believed Borders' position "is absolutely right" and that the White House action "seems on the surface unfair and unprecedented and may very well be illegal . . ."

"If Bill Borders is going to fight it," Grip said on behalf of Barry, "He can be assured of the mayor's support."

Meanwhile, commission members moved to head off quickly a possible confrontation with the White House over Border's attempt to retain the seat. The commission has just 30 days to fill the latest vacancy on the Superior Court, created on Tuesday when Reagan nominated Judge James A. Belson to the local Court of Appeals.

White House officials had asked Borders last week to resign so Reagan could make his own appointment. When he refused, the White House replaced him anyway.

"We would not have made this step if we did not think we were on sound legal ground to do so," White House Counsel Fred Fielding said. "The president felt he was entitled to have his own person representing the White House and the administration on that nomination board. The person nominated as the president's representative really should be his representative.

"If the challenge is made to the president, we will defend it vigorously because we feel very strongly it is right. We think that any litigation over that would not serve the public interest."

Borders' replacement, Lacovara, is a former member of the Watergate special prosecutor force. He resigned that post in 1974 to protest President Ford's pardon of former president Nixon. Lacovara said in an interview that he "wouldn't have taken the appointment if I didn't have a substantial reason to believe it was a valid appointment."

The replacement of Borders was one of two blows to the city in recent days on issues relating to criminal justice. Attorney General William French Smith told Barry on Tuesday that he generally was opposed to transferring prosecutorial control from the federal government to the city. City officials have long sought the transfer as an expansion of home rule.

"The trend is certainly not promising," Grip said.

One city official who supports Borders' attempt to retain this post called the White House action "removal without cause."

"The whole [administration] pitch for local government and local control [was something] District officials had welcomed," said the official, who asked not to be named. "But if they persist in this, the question is going to be raised as to whether or not they are for home rule everywhere . . ."

Fielding said that the White House would have acted earlier on the Lacovara appointment, but did not want to interfere with ongoing nominations. The Lacovara appointment had nothing to do with Borders' qualifications, he said.

If Borders' claims are not resolved in court, members of the nomination commission may be faced with the task of voting whether to seat Lavcoara or Borders. Some members downplayed the dispute, however, as a legal question with a legal answer.

"Either it is the correct interpretation the White House has put on it, or the correct interpretation that Bill Borders has put on it," said commission member John W. Hechinger, president of the chain of home-improvement centers that bears his family name.

Hechinger said the commission's remaining members voted Monday to authorize chairman Frederick B. Abramson to ask the White House counsel's office to provide the legal basis for its action, before the commission decides what action it should take, if any.

Borders said the Lacovara appointment was "an attempt to politicize the commission in direct contradiction to what [it] was set up for. I would be remiss as a lawyer and as president of the National Bar Association in not contesting this matter from a legal point of view."

Borders, who was appointed on July 2, 1980, said that he should be permitted to serve his entire five-year term on the commission, just as President Ford's appointee, Willie L. Leftwich of the Washington firm of Hudson, Leftwich & Davenport, was not replaced by Carter until his term ran out, 3 1/2 years into the Carter presidency.

Other members of the commission are appointed by the mayor, the City Council, the D.C. Bar, and the chief judge of the U.S. District Court here.