A federal judge yesterday ordered the state of Maryland to proceed with its plan to move nearly 300 mentally retarded persons confined illegally for years in state mental institutions into proper settings in communities and institutions designed for their care.

The ruling by U.S. District Court Judge Joseph Young, adopting the state's plan to deal with the illegal confinements ended a six-month-old lawsuit filed by an advocacy group for the retarded.

Under the state's plan, about 75 retarded persons will be moved to community facilities by July, according to Assistant Attorney General Michael Millemann. Others will be moved from illegal confinement in mental institutions to placement in facilities designed for the retarded. By July 1983, all of the illegally confined individuals will either be in community facilities, a newly renovated state institution or other proper facilities, Millemann said.

In 1979, Maryland Attorney General Stephen Sachs ordered an inquiry into the placement of retarded persons and reported that nearly 300 of them had languished for more than a decade in improper facilities, one designed to house the mentally ill. Under Maryland law, people suffering from mental retardation cannot be confined against their will in a state institution for the mentally ill.

"To sit for 15 or 20 years in a corner of a ward of a state mental hospital without getting any treatment . . . is shameful," Sachs said when announcing the results of his office's inquiry.

But last October, the Maryland Advocacy Unit for the Developmentally Disabled filed a lawsuit for the 300 individuals, accusing the state Department of Health and Mental Hygiene of moving too slowly in correcting the problem. The state then came up with an accelerated plan to create more community placements for the individuals and to renovate and staff a building on the grounds of Crownsville Hospital Center in Anne Arundel County according to Millemann.

The state already has spent about $2.8 million on the proposal and has budgeted another $4.5 million for its implementation in the coming year, Millemann said.

Yesterday, the executive director of the advocacy unit that filed the lawsuit said he feels that the plan has many good points and that the fact that money was appropriated for its implementation "in an otherwise tight budget year indicates the suit was successful in one aspect."

But Curtis Decker added that he has reservations about many of the specifics of the plan, particularly the fact that after it is implemented, many of the individuals still will be in institutions, rather than community facilities.

Millemann, however, said the building at Crownsville, where the state plans to house individuals who are both mentally retarded and mentally ill, will be a "transitional faciltiy," and in 1983 individuals from that facility will also start to move into the community. Community facilities, he said, range from group homes housing up to 20 persons to private apartment, where individuals receive "support services." In all cases, the state pays for their care.