The U.S. Department of Health, Education and Welfare must convince a federal judge here that its newest choice to head St. Elizabeths Hospital was chosen solely on the basic of merit, the judge ruled yesterday.

U.S. District Judge Thomas A. Flannery's ruling is the latest action in a year-long controversy over who will head the mentall hospital here, and again throws into doubt whether the whole selection process has been tainted with racial bias.

Flannery's ruling came in a case involving acting Supt. Roger Peele, who is white.Dr. Peele has successfully contended before HEW and now before the judge that he was discriminated against in June, 1976, when HEW picked a black doctor to head the facility.

The selection in June was of Dr. Ulysses E. Watson of Philadelphia. Watson withdrew in December after Peele continued to press his charges of severse racial discrimination.

Since Watson's withdrawal, HEW has named the third person who was in the original running with Peele and Watson - Dr. Charles Meredith of Maine, who is white - as the agency's selection to run the hospital.

While upholding Peele's claim of racial discrimination yesterday, Flannery said he did not have enough evidence to determine whether the bias had kept Peele from getting the job.

Therefore, he ordered a new hearing at which HEW must prove that, regardless of any racial bias at the time it was selecting from among the original three candidates, it still would have picked Meredith over Peele because of all the other factors involved.

Flannery based his ruling yesterday on two different administrative findings within HEW that said race was improperly a factor in the decision to select Watson to head the 3,300-bed institution.

"Thus, the employment decision concerning the selection of a superintendent of St. Elizabeths Hospital was not a color-blind, racially neutral decision, which is mandated" by law, Flannery said.

However, his ruling does not mean that Peele must automatically be appointed to the job by the court now, Flannery added.

Instead, Flannery said, it is up to the government to prove that Peele would not have been selected in June, 1976, even without the racial discrimination factor.

Even Meredith's appointment after a new selection procedure does not change the original issues in the case, Flannery added.

"This selection (of Meredith) is not relevant to the court's consideration of this case, for the court is only concerned with the status of the candidates at the time of the discriminatory decision," the judge said.

Flannery ordered attorneys for Peele and the government into court next Friday for the purpose of setting the date for the new hearing.