A federal judge yesterday ordered the District of Columbia government to undertake massive improvements in the treatment of residents at Forest Haven, the city's home for mentally retarded.

The order, signed by U.S. District Court Judge John H. Pratt with the agreement of the D.C. government, calls for an overhaul of procedures at the institutions, ranging from the manner in which patients are given drugs to changes in authority of the staff to punish patients by physically restraining them.

The order calls for about one-fifth of the institution's 1,000 residents to be moved from the facility, in Laurel, over the next two years to community treatment centers, and blocks any further admissions to the 50-year-old buildings in the meantime.

The order, which is the result of lengthy negotiations between attorneys for the city and federal government attorneys with the Urban Law Institute of Antioch Law School, ends for now a two-year-old suit filed on behalf of Forest Haven patients. The order calls, however, for continued monitoring of a District plan that would specify, in stages, the improvements that would be made.

Persons familiar with such orders said it is one of the most detailed entered concerning the manner in which a government institution must be operated. The city government had basically agreed earlier in the suit that care at the institution was substandard. The federal government was involved in the suit on the side of the patients against the D.C. government.

In the order, Pratt found that patients' constitutional rights to adequate care and treatment had been violated and that those violations must end.

The suit and contended that patients at the institution were sexually and physically abused, improperly imprisoned behind locked doors and forced to eat in unsanitary dining facilities. It alleged as well that the facility had almost nonexistent record-keeping, a lack of training programs and staff and supply shortages.

Six months after the suit was filed, a federal survey team said care for the institution's residents remained "improper, inconsistent and inadequate" despite city efforts to improve it.

The city must begin complying with Pratt's order by developing for each mentally retarded resident of Forest Haven an individual plan for treatment, with the specific goal of finding outside living arrangements if possible.

A specialist must be hired by the city within the next three months to supervise implementing the order, and will report directly to the director of the D.C. human resources department. The order calls for a staff to be proved that the specialist, who will be chosen by a search committee that includes representatives of the plaintiffs in the suits.

One of the problems to be confronted within the next six months under the order is locating community living facilities for those patients who can live outside the institution. An expert will be brought in to prepare special demographic studies of the Washington area to help find those facilities, the order said.

In addition, the order calls for a community advisory board to be established to monitor the new plan.

While the longer-range plans are being worked on over the next few months, Forest Haven must be operated under a strict set of guidelines included in Pratt's extensive order.

The staff must immediately investigate and report any allegations of physical or verbal abuse of patients, and can no longer place patients in "seclusion" or solitary confinement, according to the order.

In addition, the order blocks:

Any use of physical restraints as punishment, for the convenience of the staff, or as a substitute for a therapy program. If restraints are used, they can be used only for 12 hours with regular checks made by the staff.

Excessive use of medication, or use of medication as punishment, or for the convenience of the staff.

The withholding of treatment in order to "punish" a patient.

Forest Haven, situated in Maryland 22 miles northeast of the District, was built in 1925. Its 17 one and two-story buildings are in "various stages of disrepair and neglect," according to papers filed in connection with the suit.

Then D.C. human resources department director Joseph P. Yeldell blamed the problem at Forest Haven in 1976 on budget limitations and an inherited "40 years of neglect."

There was no immediate estimate available from the city on the amount of money it might cost to implement the court-ordered plan. Although the city agreed to the plan, the decree came in the form of a judicial order instead of a settlement agreement apparently because it would be more readily enforceable in that form.