The Israeli Foreign Ministry asserted today that the detention in Israel of more than 700 Lebanese Shiite Moslems -- who have become a focus of the TWA hijack drama -- and their transfer from Lebanon two months ago were consistent with international law.

The hijacking of the jetliner now being held in Beirut along with about 40 American passengers and crew members has focused international attention on longstanding legal questions surrounding Israel's continuing detention of hundreds of Lebanese citizens who have never been charged with a crime.

The Shiite hijackers are demanding the release of the Lebanese Shiites, who were swept up by Israel as suspected guerrillas or other security risks during Israel's extended pullout from Lebanon and are being held in Israel.

President Reagan, at his news conference last night, acknowledged that Israel's transfer of more than 1,000 Lebanese detainees to Israel in April may have violated international law. The prisoners were moved from the Ansar prison camp in southern Lebanon to the Atlit prison on the Israeli coast south of Haifa.

Privately, senior Israeli officials have long conceded that there is a serious "legal problem" surrounding the imprisonment of the Lebanese in Israel. But in response to Reagan's comments, the Foreign Ministry asserted that both the detention and transfer to Israel were consistent with international law.

At issue are provisions of the Fourth Geneva Convention, which deals with the treatment of civilians in time of war. Article 49 prohibits the "forcible transfer from occupied territory to the territory of the occupying power or that of any power."

It was this provision that the U.S. State Department cited in April in saying that Israel's transfer of the detainees from Lebanon violated international law "regardless of motive."

But Israel, both at the time of the transfer and in the statement today, has cited another sentence in Article 49 dealing with the movement of civilian detainees. It says: "The occupying power may undertake total or partial evacuation of a given area if the security of the population or imperative military reasons so demand. Such evacuation may not involve the displacement of protected persons outside the bounds of the occupied territory except where for material reasons it is impossible to avoid such displacement. Persons thus evacuated shall be transferred back to their homes as soon as hostilities in the area in question have ceased."

Israeli officials argue that the detention was legal because of the wave of attacks on Israeli Army units in Lebanon. They also maintain that the movement of the detainees to Israel was in accordance with the exception cited in Article 49 and was made necessary when the Israeli Army, in the process of withdrawing from southern Lebanon, dismantled its prison camp at Ansar.

"This temporary transfer became imperative as a result of the particular circumstances currently prevailing in southern Lebanon," the Foreign Ministry statement said. "This measure is permitted under the second paragraph" of Article 49.

Since early this month, holding of the prisoners also has come under question because Israel claims to have withdrawn from southern Lebanon and hence is no longer "the occupying power." However, some Israeli troops -- plus units of the Israeli-backed South Lebanon Army -- remain active there. Israel has tied the release of the prisoners to the end of hostilities in the area.

"If terrorist activity in southern Lebanon continues, it will delay the release," an official said today. He noted that about 500 Lebanese detainees already have been released and said the others would be freed "as soon as conditions in southern Lebanon will enable the Israeli Army to do so."

The Israelis have always maintained that the detention and transfer to Israel of the Lebanese were "temporary" and that all would eventually be released. This policy has been reiterated by officials here in the wake of the TWA hijacking.

Although Israel has not set a timetable for freeing the prisoners, officials say delays are likely, to avoid the impression of bowing to the hijackers' demands.