The Israeli government today was restrained by the High Court of Justice from deporting a militant West Bank mayor, Bassam Shaka of Nablus, on the basis of disputed allegation that he expressed approval of a terrorist massacre 2 1/2 years ago on the coastal road near Tel Aviv.

The High Court ordered Defense Minister Ezer Weizman, who yesterday threatened to "take measures" against Shaka for the mayor's alleged remarks, not to initiate any deportation proceedings until the Defense Ministry shows cause why Shaka should not be allowed to remain in the West Bank.

If Shaka is deported, he would be the first high-ranking Palestinian political figure to be expelled from the West Bank in more than three years. The last was Dr. Ahmed Hamza Natshe, a member of the Palestine National Council, who has since returned.

Shaka became a center of controversy in Israeli's parliament, the Knesset, when he was quoted in the Israeli press as having told Gen. Danny Matt, coordinator of the occupied territories, that acts of terrorism such as the coastal road massacre in March 1978 were justified as long as Palestinians are denied independence. In the attack on a tourist bus near Tel Aviv, 34 people were killed and 72 wounded.

Shaka's purported remarks were a sensation in the Israeli press. Matt was quoted as saying "Everything will be remembered and weighed when the time comes."

However, Shaka today denied that he had defended the coastal road massacre, and he charged the military government with waging a campaign to have him deported on charges of incitement to riot.

Shaka said that in his meeting with Matt the military commander had sought to extract a statement either condemning or supporting the massacre.

But, Shaka said, he replied simply with a "comprehensive" answer "relating it [the bus attack] to the policy of aggression adopted by the occupation in the territories and in southern Lebanon."

"I said that as long as the occupation exists by force and as long as Israel fights the Palestinians in south Lebanon, destroys villages and wipes out entire families, and as long as there is a military presence in the territories and the arrests and the settlements continue . . . there is no force in the world that will prevent armed actions by the Palestinian organizations like the one on the coastal road," Shaka said.

But the version that reached the floor on the Knesset yesterday was that Shaka has explicitly approved the 1978 massacre, prompting an outburst from both opposition Labor members and extreme right-wing parties.

Weizman interrupted a debate on new Cabinet appointments to say that he would investigate and take action against Shaka. This was widely interpreted as meaning an issuance of a deportation order.

However, Felicia Langer, who frequently represents Palestinians before Israeli courts, obtained a restraining order from the High Court. It was the second time in a month that the court had restrained government action in the West Bank, following an order to Prime Minister Menachem Begin's Cabinet to dismantle the illegal settlement at Elon Moreh, near Nablus.

The Palestinian mayors of the West Bank today began organizing a mass resignation if Shaka is deported or otherwise prosecuted.

In a rally today in Nablus, several West Bank mayors, including Mohammed Milhem of Halhul and Ibrahim Tawil of El Biera charged that the Matt allegations are part of a scheme by Israel to discredit Palestinian mayors and replace them with military rule.

Tawil and Ramallah Mayor Karim Khalaf are under indictment for assaulting Israeli security officers during a long expropriation hearing. Under Jordanian law, which still applies in civil cases in the West Bank, the conviction would represent an "offense of disgrace," and they would be forced to resign.

Whatever the outcome of Shaka's case, the deportation threats represent a sharpening of attitudes in the government against militancy by West Bank officials and public association with positions advanced by the Palestine Liberation Organization, which is regarded as illegal in the occupied areas.

Hawkish members of the Knesset, particularly, have been growing increasingly impatient with the stridency of the West Bank mayors and have repeatedly suggested stronger action against them.

In an extraordinary protest against self-censorship, news editors of Israel television tonight announced on the prime-time news broadcast that for "reasons that do not depend on the news desk" they could not show a filed report on the Nablus meeting support of Shaka. For 2 1/2 minutes, the television displayed a test pattern, and then continued with other news.

The military censor's office denied any responsibility, and the chief editor of the nightly news show, Yaacov Achimeir, said in a telephone interview that the director general of the state broadcasting authority had ordered the report of the Nablus meeting cut.

Asked if the report included inflammatory statements by West Bank leaders, Achimeir said, "Of course, I cannot deny that the mayors hate us. But are we supposed to report only good news? In my point of view, this was genuine news."