U.S. District Judge Gerhard A. Gesell ruled yesterday that a section of the District's election law requiring elected city officials to resign their offices before they can run for another is unconstitutional and cannot be enforced.

The ruling came in a suit brought by City Council member Marion Barry, who has announced his candidacy for mayor and would have to resign under the law by July 5 to conduct his campaign.

Gesell said Congress stated no reasons for including the challenged provision in the D.C. Home Rule Charter and he was "hesitant to accept" as constitutional such as unusual provision under those circumstances.

"It is difficult to understand what public purpose, if any, is served by this damper on the vigor and vitality of elections for the Districts highest offices," Gesell said in his opinion released yesterday.

He said the provision "not only deprives Barry and his supporters of protected rights, but also threatens the full and free political participation of substantial number of leading elected officials."

The city government had argued that the provision was useful because it avoided the cost of separate special elections to replace persons elected to higher office, maximized continuity in office and encouraged devotion to duty by an incumbent in his present post.

The provision specifically states that no elected city official may stay in office and run for another city office unless his present term express before the beginning of the term of the job he is seeking.

In Barry's case, he is running for a term that begins next January. His council term does not expire until 1981.

Barry said late yesterday that he was "elated and gratified" by the ruling, and that it demonstrates "we need more and not less home rule." Although Gesell said an appeal in the case is certain and the issue should be finally resolved by July 1, Barry said he thought any appeal by the District would be "political and not legal" and a "waste of money."

Barry contended in his suit that the provision violated his First Amendment right to free expression and his Fifth Amendment right to equal protection, because it discriminates between two classes of officeholders.

Gesell rejected the District government's argument that the provision allows "continuity and devotion to duty" of officeholders.

He said the deterrent effect of the provision operates "against the public interest by reducing the pool of best-qualified candidates available to run for the District's highest offices."

In fact, he added, 17 of the city's 26 elected officials would be constrained from running for election this year by the challenged provision.

Gesell said the provision penalized persons such as Barry financially as well, because it forces persons to give up their salaries while running for office.

"This is a substantially penalty which impacts more severely - perhaps reclusively - on those officeholders of slight wealth," Gesell said.

The District also had argued that it would be impossible for Gesell to strike down any single portion of the elections law without voiding the complete act. Gesell rejected that argument as well.

He said he was ruling only that "given the election system in the District of Columbia, Congress may not, consonant with the First and Fifth amendments, require an elected official in the District to leave office prior to qualifying as an eligible candidate for election" to another office.

In earlier arguments on the case, Gesell stessed that his ruling affects all future elections here, and not just the one involving Barry. "Mr Barry is (only) a manifestation of the operation of the statute," the judge said.