The United States voted against Israel in the Security Council tonight for the first time since the controversial vote March 1 that was repudiated two days later by President Carter.

The subject that stimulated tonight's vote was the same -- Israel's expulsion of two West Bank mayors, Fahd Kawasme of Hebron and Mohammed Milhem of Halhoul, who were here for the debate. The council demanded that they be allowed to return home.

After the vote, the two exiled Palestinian mayors announced that they would stage an indefinite hunger strike on the U.N. premises to force Israel to obey.

Secretary General Kurt Waldheim agreed, in a highly unusual move, to let the demonstrators camp in a private delegates' lounge adjacent to the Security Council chamber.

The resolution, adopted unanimously by the 15-member council, "declares it imperative that the mayor of Hebron and the mayor of Halhoul be enabled to return to their homes and resume their responsibilities."

U.S. Ambassador Donald F. McHenry, the president of the council this month, explained the American vote by saying the Geneva convention on the treatment of civilians in time of war "prohibits deportations, whatever the motive of the occupying power."

The United States abstained several times during the presidential campaign in U.N. votes touching on the occupied territories. McHenry alluded tonight to "cynic" who said the vote would have been different before the election, "but one cannot be hostage to cynics."

The two mayors were expelled May 3 after a terrorist attack that cost the lives of six Jews near Hebron. The Arab mayors later were allowed to return to Israel for a judicial review of their case and then were expelled once again earlier this month. They appealed to the council for help earlier this week.

All council members, including McHenry, criticized the latest expulsion.

After the vote, Milhem, 51, took the floor to say: "We consider that this building belongs to everybody, especially those who are oppressed. We have decided to stay in trust of this organization," he added, explaining that the demonstration here would give the United Nations "more credibility." t

Later, reporters were allowed into the lounge, known as the "quiet room," an elegant backwater graced by writing tables, an original Picasso tapestry and a breathtaking view of the East River.

Milhem, pointing to a couch, declared that "I would like to sleep here." He announced that he and Kawasme, 41, had already fasted in an Israel jail and would do so here "to show our faith in the Security Council resolution." He said the length of the hunger strike "will be decided later on."

A spokesman for Waldheim said the secretary general had placed the lounge at their disposal and would provide security and medical care if necessary.

Asked why these demonstrators are being allowed to stay while others who protest are removed from the premises and handed over to New York City police, the spokesman said: "In this case there has just been a unanimous Security Council resolution. It is not the same as coming in from the street."

Israeli Ambassador Yehuda Blum told the council that Israel has an independent judiciary "with an enviable reputation" that handled the case of the two mayors and that "we cannot therefore accept any attempt to interfere with the judicial process of our country."

He called the council hypocritical for holding three debates and adopting three resolutions on the two mayors while ignoring the Iranian-Iraqi war, the Soviet invasion of Afghanistan, the Libyan invasion of Chad and the ordeal of the American hostages in Iran.

The resolution the United States supported today is less controversial than the one it backed and then repudiated in March. That one dealt with Israeli settlements in the occupied Arab territories, spoke of the territories as "Palestinian" and included Jerusalem among them. Both of these concept brought protest from the Israelis and the American Jewish community. President Carter later said that a "failure of communication" had caused the yes vote instead of abstention.

At the time, the reversal was widely interpreted as an effort to appease American Jews whose votes were critical to the Carter campaign.