The Supreme Court, in a decision that could force Virginia to refund nearly $400 million in income taxes to federal pensioners, ruled yesterday that states must pay refunds or otherwise make adjustments for taxes that have been unconstitutionally collected.

The court, ruling in a case involving a Florida liquor tax that unconstitutionally discriminated against out-of-state producers, unanimously rejected the state's argument that it should not be forced to provide refunds because of the disruptive effect on the state's budget.

In a second case, the court said a 1987 decision striking down a Pennsylvania highway tax that discriminated against out-of-state truckers should not be applied retroactively to force Arkansas, which had a similar law, to repay taxes collected before the date of the decision.

But five justices in that case -- four dissenters joined by Justice Antonin Scalia -- appeared willing to apply decisions retroactively in situations such as the Virginia case, in which federal pensioners are suing the state for $400 million in state income tax refunds.

Scalia said decisions should in general be applied retroactively but refused to do so in the Arkansas case because he disagreed with the original ruling striking down the highway tax.

"I would say it looks good for {federal retirees} in Virginia," said Kenneth S. Geller, who represented the truckers in the Arkansas case. He said the impact of the two rulings was "fairly disastrous" for states.

Virginia's problem stems from a Supreme Court decision last year that states cannot tax federal pensions if they exempt state and local government retirees from the same taxes.

The decision, Davis v. Michigan Department of the Treasury, invalidated provisions in 23 states and had the greatest impact on Virginia, home of 200,000 federal and military retirees. The state called a special session of the legislature to deal with the problem and changed the law to treat state and federal pensioners equally, but is still facing a lawsuit by retired federal employees seeking a refund of back taxes.

Virginia and other states had been closely watching the cases decided yesterday to determine whether they will be liable to make as much as $2.6 billion in tax refunds.

Virginia Attorney General Mary Sue Terry, in a friend-of-the-court brief joined by Maryland and 19 other states, warned of a potentially "devastating" impact if states are exposed to such liability.

"A decision that federal law mandates tax refunds from a state treasury removes from each state the critical ability to direct its financial future," the brief said.

The court in the Florida case, McKesson Corp. v. Division of Alcoholic Beverages and Tobacco, rebuffed that plea.

In a decision written by Justice William J. Brennan Jr., the court said that so long as states force taxpayers to promptly pay taxes, even if the taxpayers contend the taxes are unconstitutional, the due process clause "obligates the state to provide meaningful backward-looking relief to rectify any unconstitutional deprivation."

The court emphasized, however, that states are not automatically required to refund the entire amount of the unconstitutionally collected tax but have other options, such as requiring those who got preferential treatment to pay additional taxes or implementing a combination of the two.

In the second case, American Trucking Associations v. Smith, the court said in a decision written by Justice Sandra Day O'Connor that the 1987 Pennsylvania tax decision should not be applied retroactively because states such as Arkansas had no way of forseeing the ruling.

Several other states were in the same position as Arkansas, and at least $630 million in refunds was at stake in the case.

Justice John Paul Stevens, in a dissenting opinion joined by Justices Brennan, Thurgood Marshall and Harry A. Blackmun, said the ruling should be applied retroactively.

"Fundamental notions of fairness and legal process dictate that the same rules should be applied to all similar cases on direct review," they said.

Attorneys on both sides of the Virginia case claimed victories from the Supreme Court rulings but said the Virginia situation will have to be clarified by other pending court cases.

"We're real happy about it," said David Weiser, a Washington attorney for the Virginia Federation of the National Association of Retired Federal Employees. "This doesn't put an end to it, but we think we got more ammunition" than the state from the rulings, he said.

Terry issued a statement declaring a clear-cut victory for Virginia's position. "This is good news for Virginia taxpayers," Terry said.

Deputy Attorney General Gail Starling Marshall said state officials were optimistic that the Davis ruling would not be applied retroactively based on the plurality's interpretation in the Arkansas trucking case because it was "a completely unforseen development in the law." But she said she did not have any comment on Scalia's view that decisions generally should have a retroactive effect.

Virginia could be forced to make refunds for 1985 to 1988 if the Davis decision is applied retroactively. Federal retirees lost before Alexandria Circuit Judge Donald H. Kent in February, but have appealed his ruling to the Virginia Supreme Court.