A federal judge ruled yesterday that the approximately 125 members of Congress who live in Washington's Maryland suburbs do not have to pay the Maryland income tax.

U.S. District Judge Frank A. Kaufman ruled in Baltimore that Congress had the right to pass a law exempting its members from the local taxes of Maryland, Virginia and the District of Columbia to "aid itself in the performance of its duties."

Maryland officials said yesterday they plan to appeal the decision to the Supreme Court if necessary to win permission to collect the more than $225,000 in annual taxes from senators and representatives living in the state.

"I'm going to recommend an appeal based on the fact that those people came to Maryland, they live here, and should be assessed taxes like everyone else," said State Comptroller Louis Goldstein, who has been attempting to collect the taxes for several years.

Goldstein's efforts led several congressmen to ask the Justice Department to file the suit against Maryland that Kaufman decided yesterday in a 40 page opinion. The suit, filed in July 1978, also asks the court to order refunds of the taxes that have been payed to Maryland by current or former congressmen.

Kaufman said he would issue his ruling on the refund issue "at a later time."

The congressmen who asked for the suit argued that they would be "double taxed" by having to pay Maryland taxes in addition to those of their home state. They said such taxation could prevent less wealthy politicians from running for Congress because of the increased financial burdens of living close to Capitol Hill.

Their suit argued that Congress had the right to exempt groups from local taxes when there was evidence that the levies would damage the effectiveness of the federal government.

Kaufman agreed. "If Congress determines that taxes such as the Maryland taxes in question . . . impede Congress' ability effectively to execute any or all of its constitutional powers," his opinion said, "Congress possess the power to enact whatever reasonab(le) legislation it deems necessary."

As an example, lawyers for the Justice Department had singled out the Soldiers and Sailors Civil Relief Act of 1940, which exempted servicemen from paying taxes in the area where they were stationed.

Goldstein said yesterday he has never attempted to "doubly tax" congressmen because those who pay taxes in their home states are exempted from the statewide income tax and have been charged only Maryland's "piggyback" income tax, which goes to local governments.

Goldstein said only 25 congressmen would have to pay the statewide tax under Maryland rules, and that most of the $225,000 he wants to collect would go to Prince George's and Montgomery counties, where most of the congressmen live.

Besides vowing to appeal the court decision, Goldstein criticized the affected senators and representatives for asking the Justice Department to file the case in the first place.

"It is shameful," he said, "that the members of Congress have brought the legal resources of the Department of Justice into what is essentially an individual income tax matter. Our dispute is not with the Justice Department. It is with the few members of Congress who are benefitting by not paying taxes."

Maryland's own senators and representatives have to pay the state taxes. Both senators and most of the state's House delegation strongly opposed the 1977 law granting the tax exemption and supported the efforts of state officials to collect from their colleagues.