A federal judge ruled yesterday that the CIA overstepped its authority when it fired an employe on national-security grounds after he acknowledged taking part in homosexual activities.

U.S. District Court Judge Barrington D. Parker called CIA Director William J. Casey's decision to fire the worker "improper, unreasonable, an abuse of discretion and both procedurally and substantively flawed."

Parker ordered the CIA to reinstate the employe -- identified only as John Doe, a nine-year agency veteran -- to administrative leave while the agency reconsiders the firing in light of the judge's ruling.

Doe's case, said Parker, "does not reflect or even suggest that overriding national-security concerns are at stake or that affording the plaintiff Doe the relief he seeks might disclose matters that would place at risk such concerns . . . "

"In sum, the state of this record does not support the government's position that the [director] should have carte blanche authority and limitless discretion, free of judicial review."

American Civil Liberties Union lawyer Mark Lynch, who represented Doe, called Parker's ruling "a really dynamite decision."

It stands for "the proposition that the CIA can't fire people for [just] any reason at all," Lynch said.

It means, he said, "that due process applies to the agency's administrative actions."

Kathy Pherson, a CIA spokesman, said agency lawyers had not seen the ruling and would have no comment.

According to Parker's ruling, the employe was hired in 1973 at age 17 as a clerk typist. He was promoted four years later to electronics technician and in 1978 was picked for the CIA's upward mobility program.

Doe "became aware" of his homosexuality in 1976 and voluntarily mentioned it to an agency security officer in January 1982, the judge said.

During his employment, said Parker, "there was no indication that, at any time, he disclosed classified information to unauthorized persons, that he ever engaged in any conduct with any one individual which compromised security with foreign nationals or anyone else, or that his homosexuality disrupted or affected his duties and responsibilities in any manner."

Doe was placed on administrative leave a month later.

In April 1982, he was informed that the CIA's Office of Security had decided that the "circumstances of his homosexuality" posed a security threat, according to the ruling.

Parker said Doe asked for an explanation but received none. He was asked to resign but refused.

In a letter May 11, 1982, Doe was informed by the agency's deputy general counsel that Casey "deemed it necessary" to fire him, citing the National Security Act.

Parker said Doe received no other explanation or statement of reasons and was given no chance to argue against his dismissal.