NEWARK, N.J. (AP) _ A federal judge today overturned a law barring some former mental patients from buying guns, ruling that it unfairly singles out individuals once treated for mental illness.

The law prevents prevents people who were involuntary committed to an institution from showing they are capable of handling and buying firearms.

U.S. District Judge H. Lee Sarokin said the law treats former mental patients differently from ex-convicts and denies them the opportunity to show they no longer present a danger. Another section of the law gives individuals convicted of crimes that did not involve a gun the opportunity to show they can handle a gun.

''Persons who have conquered past mental illness are entitled to the same consideration and rights,'' the judge said. ''The court can find no rationale for the statute but an archaic, stigmatizing, unreasoning fear of the mentally ill.''

But Sarokin delayed the effective date of his ruling for 120 days to give Congress time to correct the constitutional defects he identified in the law.

He added that he did not mean to suggest that all former sufferers of mental illness should be permitted to own firearms.

Sarokin also said the regulation of purchases and sales of firearms for the public's safety was a legitimate and substantial objective.

The case arose from a lawsuit filed against the federal government by a West Orange man who was hospitalized for 23 days in 1971 after he was diagnosed as suffering from an acute schizophrenic episode with paranoid features.

The man voluntarily entered a hospital and had no previous history of mental illness, the judge said.

He was committed by court order for the final five days of his stay at the request of his doctor, Sarokin noted.

The patient was released after his doctor determined that his condition had improved, and there was no evidence that the man was ever hospitalized again for mental illness, the judge said.

Ten years later, the man applied for and received state approval for a firearms purchase identification card.

But more than a year later, a sporting goods shop refused to sell him a gun when he responded ''yes'' to a question on a standard federal questionnaire that asked whether the applicant had ever been committed to a mental institution or found to be mentally ill.

The man then applied to the U.S. Department of the Treasury's Bureau of Alcohol, Tobacco and Firearms for relief from the firearms requirement.

His application included a certification from the physician who sought his commitment that he no longer was suffering from any mental disability that would interfere with his handling of firearms.

The federal government denied the application, citing the law that allows only ex-convicts - not former mental patients - to apply for an exemption from the law.