The Supreme Court ruled yesterday that parents generally may not turn to federal courts to try to regain custody of children permanently taken from them by state officials.

The court held, 6 to 3, that federal courts are barred from interfering in state custody decisions by the "exceptional need for finality in child-custody disputes" and the strong state interest in regulating family matters.

The ruling in Lehman us. Lycoming County Children's Services Agency ends Marjorie Lehman's eight-year attempt to block Pennsylvania from permanently depriving her of custody of three sons she voluntarily turned over to the state for foster care 11 years ago.

The state refused to return the children on the grounds that Lehman's low social and intellectual development made her incapable of adequately caring for them.

After losing her custody battle in the Pennsylvania courts and being denied review by the Supreme Court, Lehman asked a lower federal court to declare unconstitutional a Pennsylvania law allowing termination of parental custody without any showing of abuse or neglect.

Yesterday's decision, by Justice Lewis F. Powell Jr., held that the federal court didn't have jurisdiction to hear that challenge.

Allowing federal review "would prolong uncertainty for children such as the Lehman sons, possibly lessening their chances of adoption," Powell said. "There is little that can be as detrimental to a child's sound development as uncertainty over whether he is to remain in his current 'home,' under the care of his parents or foster parents, especially when such uncertainty is prolonged."

Lehman had sought review under the powerful tool of habeas corpus, which among other things gives federal courts power to determine whether a person's custody is legal. Habeas corpus is used mostly by prisoners challenging the constitutionality of their convictions, however, and children in foster homes aren't in custody in that sense, Powell said.

Lehman's sons are not in state custody, but "in the 'custody' of their foster parents in essentially the same way, and to the same extent, other children are in the custody of their natural or adoptive parents," Powell said.

Justice Harry A. Blackmun disputed the majority's finding that the children weren't in custody. The state, he said, "decides where they will live, reserves the right to move them to new physical settings at will, and consents to their marriage, their enlistment in the armed forces, as well as all major decisions regarding medical, psychiatric, and surgical treatment."

While saying that he could "sympathize" with the majority's concerns, Blackmun argued that federal courts could deal with those problems by exercising discretion not to hear most custody cases.

Justices William J. Brennan Jr. and Thurgood Marshall joined in the dissent.

The Supreme Court ruled earlier this year that states seeking to deprive parents of permanent custody must prove their case by "clear and convincing" evidence, and not merely meet the lower "preponderance of the evidence" standard.

With yesterday's ruling, the court appeared to have reached a middle ground on the custody issue, holding state courts to a high standard of proof but giving them sole jurisdiction over such cases.

In other action, the justices ordered a lower court to rethink its finding that topranking Justice Department officials can be sued for failing to cut off government funds to police departments that allegedly discriminated against blacks and women.

In a one-sentence decision, the court directed the federal appeals court here to reconsider the case, taking into account a Supreme Court ruling last week that makes it more likely for lawsuits against federal officials to be dismissed without a trial.

Officials named in the suit are former Law Enforcement Assistance Administration officials who were sued in September, 1975, for failing to cut off LEAA grants to 11 police agencies accused of race and sex discrimination.

The complaint contended that the officials perpetuated the police agencies' discriminatory practices by refusing to punish them by cutting off their LEAA grants.

The law enforcement agencies named in the complaint were the police departments of Philadelphia; New Orleans; Des Moines, Ames and Newton, Iowa; Richmond and Oakland, Calif.; Portland, Ore.; Honolulu; the Indiana State Police Department and the Wayne County, Mich., Sheriff's Department.

The administrators of the LEAA program, which funneled billions of dollars to local and state police departments before expiring this year, say they preferred to seek police agencies' voluntary compliance with civil rights laws first.

Those filing suit, however, contended that the LEAA law mandated fund cutoffs if a police agency discriminated on the basis of race, religion, sex or national origin.