A U.S. District judge ruled yesterday that the federal government acted illegally when it began to charge government employes for parking spaces, a decision that could mean that thousands of employes would get refunds on parking fees they have paid since November 1979.

Judge Harold H. Greene immediately blocked the government from any further collection of parking fees because the fee program, implemented by former President Carter, had not been approved by Congress.

"We are ecstatic," said attorney Robert M. Tobias of the National Treasury Employees Union, which joined in the case after it was initially brought to the court by another union, the American Federation of Government Employees.

Attorneys for the unions said yesterday that they would ask Greene to order refunding of the money already collected through the fees, which are usually paid on a monthly or bi-monthly basis. James R. Rosa, general counsel to the AFGE, said late yesterday that Greene's order means that federal employes can park for free as of today, although he added "I'm not sure every parking lot run by the government will get the word" quickly.

Meanwhile, Royce C. Lamberth, chief of the civil division of the U.S. Attorney's office here, said the government would ask the federal appeals court today to delay Greene's order until his decision is reviewed by the higher court.

Estimates are that the parking plan affects 75,000 people in Washington and 350,000 nationwide. The government estimates that the plan so far has generated between $15 and $23 million in revenues. Officials said yesterday, for example, that the General Services Administration alone had collected $2.2 million in parking fees that may have to be refunded.

Former President Carter, in a nationwide speech in April 1979, first announced that steps would be taken to eliminate free parking for federal workers and linked the plan to the government's overall efforts to cut down on energy consumption.

Greene said, however, that the 1975 Energy Policy and Conservation Act said that such programs to reduce energy consumption could be implemented only if Congress concurred. Such congressional approval was not obtained in the parking fee program. Greene said.

The government argued that the parking plan was authorized under 1972 legislation that allowed the General Services Administration to charge other federal agencies for space they used on government property. Greene said, however, that that law was directed at economy in construction and maintenance requests, not energy conservation.

Carter, Greene said, could not rely on the general authority of that 1972 law to justify the pay-for-parking plan when the 1975 Energy Conservation Act addressed itself directly to measures designed to cut down on energy use.

"From the point of view of swift and dramatic action," Greene noted, the Office of Management and Budget, which established the parking policy, chose the 1972 law because it avoided the time-consuming process of congressional review.

Nevertheless, Greene said, the former president was required to act within the specific purposes of the Energy Conservation Act.

Greene said the government could not ignore the fact that the parking plan falls directly under the Energy Conservation Act because it "imposes restrictions on the use of energy and its purpose is to reduce energy consumption."

Under the act, greene said, such a plan cannot be put into effect unless the president first submits it to Congress for approval.

In his decision yesterday, Greene asked lawyers for both sides to submit legal arguments to him within 15 days on the question of whether the federal employes who paid parking fees are entitled to a refund.