Former Solidarity chairman Lech Walesa was detained for nine hours by police today as he drove from Gdansk to Warsaw to pay respects to heroes of the 1943 Warsaw Ghetto uprising. Walesa was freed this evening but his wife Danuta reported that he received a summons to appear Tuesday morning at police headquarters in Gdansk.

In Warsaw, authorities for the second day blocked an unofficial commemoration of the uprising by locking the gates of the Jewish cemetery to a crowd of about 100 people who had come to lay a memorial wreath.

In a surprise move, however, Polish leader Gen. Wojciech Jaruzelski invited representatives of the foreign Jewish groups participating in the official commemoration program to a one-hour meeting today. One American Jewish leader termed the session "insubstantial," but a Romanian rabbi said it drew a pledge from the Polish chief to fight anti-Semitism in Poland.

Jaruzelski's unexpected involvement appeared to be an attempt to smooth over an elaborate 40th anniversary celebration that has turned into a public relations headache for the Warsaw government.

Instead of being applauded as a good-will gesture to a people who have been persecuted in Poland by past Communist regimes as well as by Nazis, the extensive memorial program has largely backfired by drawing attacks that it is an act of political exploitation and by prompting independent commemorations that Polish security forces have sought to thwart.

Walesa himself was on his way to lay flowers and pay private tribute in the former Warsaw Ghetto neighborhood when police stopped his car and escorted it to a station near Olsztyn, about a third of the way to Warsaw from Walesa's seaport hometown of Gdansk.

Riding with the former labor leader was his close friend and priest, the Rev. Henryk Jankowski, as well as a driver and another companion. An American television crew that had been trailing the Walesa car was also briefly detained by police.

Jankowski, who was released before Walesa after more than five hours of questioning, declined to provide details of the interrogation but said sarcastically of the detention: "This is another one of their gestures of national accord. They stop people going about their normal business and try to implicate them in God knows what."

It was the second time during the past week that Walesa has been detained by police following his announcement of a clandestine meeting he held with underground leaders. The meeting was a humiliation for the government and Walesa who, upset at subsequent attempts by authorities to interrogate his wife and staff, has threatened to repeat it.

Walesa had been expected to join a group of old Polish resistance fighters and others who gathered outside the Jewish cemetery on the outskirts of the former ghetto at 5 p.m. today. The plan was to lay a wreath of flowers at the memorial to Michal Klepfisch, a ghetto hero.

Although the burial ground normally closes to visitors at 3 p.m., organizers of the unofficial event said they had received earlier assurances from the cemetery's caretaker that the wreath laying could take place two hours later. But when the group gathered outside the cemetery, it was advised that "Jewish authorities" had ruled against opening the graveyard for the special ceremony.

A short statement was delivered by Jozef Rybicki, a former Warsaw resistance chief, who called the example of Jewish fighters in the ghetto "an inspiration" for the Polish resistance against the Nazis. The flower wreath was left hanging on the high, closed metal gates of the cemetery.

Absent today were the crews of uniformed militia that yesterday broke up a solemn, unofficial commemoration ceremony at the main ghetto memorial. But a number of plainclothed security agents could be seen closely watching today's gathering. Among those participating were former top Solidarity union advisers Tadeusz Mazowiecki, onetime editor of a Roman Catholic weekly, Bronislaw Geremek, a historian, and Wladislaw Sila-Nowicki, an attorney.

A highlight of the official 40th anniversary celebrations came earlier in the day at a dignified ceremony opening the restored Nozyk Synagogue, Warsaw's only Jewish house of worship. Reconstructed by the Polish government at a cost of 120 million zlotys ($1.4 million)--the Germans had turned it into a stable--the marble-floored structure is expected to serve more as a symbol and museum piece than as an active center.

"The flame of Jewish life barely flickers here today," Henry Taub, whose American Jewish aid group has close contact with the Polish Jewish community, observed mournfully during the inaugural service.

Referring to the meeting with Jaruzelski, Grand Rabbi Moses Rozen of Romania told the synagogue audience that the general "spoke to us as a great humanist. He assured us the Polish government is fighting anti-Semitism."

But asked later about the encounter, Rabbi Alexander Schindler, president of the Union of American Hebrew Congregations, said it was little more than a "courtesy call" occasioned by an invitation from Jaruzelski that was extended yesterday afternoon.