A judge cleared the way yesterday for the new majority of the Montogmery County School Board to replace controversial School Superintendent Charles M. Bernardo this fall.

County Circuit Judge John F. Mcauliffe ruled that the previous school board acted illegally last June when it gave Bernardo a four-year extension of his contract.

Under the ruling, Bernardo may be dismissed as early as Oct. 1, when his original contract expires.

Mcauliffe's decision came in a suit filed by the new board majority, which pledged to seek Bernardo's ouster in campaigning before the election last Nov. 7.

Bernardo, recruited four years ago to make changes in the Montgomery school system that were in part dictated by declining enrollment, called yesterday's decision "scandalous" and declared he will take the case to the Maryland Court of Appeals.

Speaking in a voice that occasionally quivered with emotion. Bernardo said, "When your competence is never brought into question, when you've dutifully fulfilled all obligations of your office, and when your contract is dishonored by both the political system and the judicial system, one can't help but lose faith."

Among the things that made Bernardo a target of the board's new conservative majority were a reorganization of the school bureaucracy that alienated some administrators, the closing of 23 schools on his recommendation that irritated many neighborhood groups and the institution of a mandatory course in black culture that some teachers thought was unnecessary.

At issue in the suit that challenged the extension of Bernardo's contract was whether the former school board circumvented state law when it extended it last June 15, more than 15 months before such an extension was required.

State law specifies that superintendents should be hired in February for four-year terms beginning the following July. But Bernardo was originally hired in September 1975 after former Superintendent Homer O. Elseroad resigned midway through his term.

School board attorneys, whose argument was upheld by the judge, said the former board should have waited until the end of Barnardo's contract next October before reappointing him or appointing someone else. The current board may fill the post on a temporary basis in October, then make a permanent appointment in February.

Board attorney Roger Titus also said that the new board, with its consercative majority elected last November, had a right to decide whom it wants as superintendent.

Board member Elizabeth Spencer, who was board president when Bernardo's contract was extended, said the action was taken for two reasons: to honor a contractual commitment that the board must give Bernardo a year's notice of its intent regarding an extension, and to prevent the superintendent from becoming a campaign issue in last fall's election.

The contract renewal produced the opposite effect on the campaign, Board candidates Joseph Barse, Eleanor Zappone and Carol Wallace, who now make up the board majority along with incumbent Marian Greenblatt, campaigned vigorously for Bernardo's ouster. Their slogan "Budget, Basics and Bernardo" indicated their aims of cutting expenses, returning to basis in teaching and firing the superintendent.

They said Bernardo allenated teachers and staff by massively reorganizaing the system's central administrative offices in an effort to streamline the bureaucracy in the face of declining enrollments and tight fiscal constraints.

He acted in a vacuum, they said, and, according to Henry Heller, head of the Montgomery County Education Associaton, he ended up losing the respect of "most everyone in the system."

During the campaign Wallace Barse and Zappone said Bernardo's educational innovations-such as the two-year-old computer-assisted instructional program in basic skills and the mandatory black studies course for school employees-lowered the morale of teachers, who they said were burdened enough as it was.

More than anything else, the conservative board members said they wanted to redistribute the school budget from administration to the classroom, refocus instruction toward basic studies, and dismiss Bernardo, the figurehead of an administration they thought was insensitive to the teachers and traditional educational objectives.

The black culture course has been made voluntary by the new majority in a move that created a furor in the black community.

In budget actions so far they have trimmed more than $4 million from administrative offices, and added more than $1 million in expenditures for additional textbooks and teachers.

"I'm simply ecstatic," Greenblatt said yesterday. "This has been a long process and the court has vindicated us." She said the question of who the board will hire as a temporary superintendent when Bernardo's term expires in October, will be taken up at the board's first executive session, next Tuesday.

"We need someone we can feel confident with, someone who will implement the policies of this board," Greenblatt said.

Bernardo, saying he intends to stay in his job until 1983, called the ruling "most unjust and most unfair." He said it "will have a negative, precedent setting impact nationwide on superintendents' contracts. . .

"I held out hope that the legal system would be above politics, but I now realize that that hope was naive," he said.

Mcauliffe said his decision "has nothing to do with Bernardo's integrity or ability, which have always been above reporach. It's a pure question of law and interpretation of legislative intent."

Among those rallying to Bernardo's support yesterday was Joyce Constantine, head of the County Council of PTAs who called the decision "bad for the school system and parents alike. Much of what the superintendent tried to do will beair now."

Herbert Bennington, a former board member, said a legal defense fund is being established to aid Bernardo's appeal.