Maryland's highest court ruled yesterday that a state law that says former judges on state pensions cannot earn income as lawyers is unconstitutional.

The Court of Appeals ruled in favor of former Prince George's County judge Richard V. Waldron, who opened a law practice in 1979 while continuing to collect a $24,000 pension for his service on the District Court.

The appellate court tossed out a statute that appeared on the books in 1962 and was modified in 1974. It says a judge who "retires and accepts [a pension] may not . . . engage in the practice of law for compensation."

Under that law, judges who wanted to practice law had to postpone receiving their pensions. The 60-page ruling published yesterday "means that judges can say, 'please send me my pension,' and immediately hang out a shingle," according to Assistant Maryland Attorney General Alfred Scanlan, Jr.

The state estimated in 1978 that there were more than $227,000 in pension payments owed to seven retired judges who had postponed their pensions in order to practice law. Now Florence Bukosky of the state Department of Personnel estimates that as many as 16 retired judges might qualify for immediate pensions at a cost to the state of more than $500,000.

Waldron, who retired from the bench when he was not recommended for reappointment after his 10-year term expired in 1977, first challenged the law in that year in a case that made it all the way to the high court but failed to resolve the constitutional questions. Then, in the fall of 1979, he opened his Riverside law practice in defiance of the statute. "I'll just let them come after me; the law is unconstitutional," he said.

"I had the temerity or lack of judgment to challenge the establishment and I won because I was right," said Waldron yesterday, adding, "It's nice to have your opinion confirmed."

The state had sought an injunction against the judge in November 1979, arguing that the law should be preserved for its value in maintaining an image of the impartial judiciary clearly above the world of lawyers pleading and maneuvering for clients.

"We wanted to instill confidence in the judiciary," said Assistant Attorney General Scanlan. "If you have retired judges going into private practice, the public might think his fomer colleagues are cutting him a better deal."

But the purpose of the law when it was adopted was never clear. Waldron says it was special interest legislation, never subjected to a committee hearing. He traces its origins to lawyers who were jealous of a judge in Cecil County who retired, opened a practice, and snatched up a lot of business.

Judge J. Dudley Digges, writing for the Court of Appeals, rebuffed that reasoning, and threw out the law on two grounds: It unfairly singles out judges in violation of equal protection provisions, and it constitutes a violation of the seperation of powers principle when the legislature's laws infringe on the right of the judiciary to regulate the practice of law.

The latter point could have reaching effects, Scanlan says, noting that the decision shows the court unequivocally staking out judicial territory. "This opinion will play a major role in whatever litigation arises involving the overlapping functions of the judiciary and the legislative branches," he said.