Poland's martial-law authorities today detained Lech Walesa, the leader of the outlawed Solidarity trade union, to prevent him from addressing a planned unofficial memorial rally for workers killed by security forces 12 years ago.

The 39-year-old Solidarity leader, who was only freed from internment last month, was taken into custody at his home on the outskirts of Gdansk this morning. After holding him for more than nine hours, police released him this evening, long after the time scheduled for his speech.

The rally, in memory of a workers' uprising along the Baltic Coast in December 1970, failed to take place. Gdansk was saturated with thousands of riot police, known as ZOMO, who kept strict guard throughout the day around Walesa's apartment and the monument to fallen workers near the Lenin Shipyard.

Workers streaming out of the shipyard at the end of the first shift at 2 p.m. laid wreaths at the foot of the monument under the watchful eyes of the ZOMO. Several hundred people chanted slogans like "We want Lech" and "Solidarity," but they were dispersed by tear-gas grenades when they marched in the direction of the central railway station.

It was the second year in succession that Walesa was prevented from keeping a promise to return every year to the spot where security forces first opened fire on his colleagues from the Lenin Shipyard in December 1970. Last year he was interned along with thousands of other Solidarity activists following the imposition of martial law on Dec. 13.

Two years ago, on Dec. 16, 1980, Walesa joined senior officials of the Communist Party and Roman Catholic Church in unveiling the soaring monument of three 140-foot-high crosses. Together they solemnly pledged to solve their differences by negotiation and never allow the December 1970 tragedy, in which at least 55 workers were killed, to be repeated.

The decision to prevent Walesa from speaking in public this year appears to be part of a carefully worked-out strategy to deprive him of a public platform. After failing to win him to their side, the Communist authorities now seem intent on destroying him as a serious political force in Poland.

In his few public statements since his release from internment, Walesa has taken a moderate and cautious line. But he has made clear that he sticks by all his previous beliefs--and intends to continue fighting for workers' rights as he defines them. This insistence on an independent political role is apparently unacceptable to the authorities.

In the speech that he had prepared to give today, Walesa virtually acknowledged that Solidarity had been defeated as an organization--but insisted that the idea lived on inside the minds of ordinary Poles. He called on Poles not to give up, but to continue an open struggle for independent institutions to represent them.

The speech was made available to Western correspondents in Warsaw two days ago and has since been broadcast back to Poland by Western radio stations. The government is apparently attempting to deny even this platform to Walesa by stepping up jamming of the airwaves over the past few days, particularly on medium-wave frequencies, which until now had attracted the largest audiences.

Today's security measures amounted to the most extensive police operation in Gdansk for months. The entire housing project where Walesa lives was sealed off by ZOMO from dawn and all nonresidents were prevented from entering. About 40 foreign journalists, including this correspondent, were detained at a local police station for one to four hours after being stopped at police roadblocks while attempting to enter the area.

Walesa himself was taken from his home at 10:25 a.m. by six police officers in battle dress carrying crowbars and a submachine gun. An eyewitness said that he was given no explanation as to why he was being taken away and was bundled into one of two Mercedes cars.

According to Danuta Walesa, who was contacted by telephone after her husband's return, Walesa spent most of the next nine hours being driven around Gdansk Province. State radio said he had visited a department of the local people's council to discuss financial matters -- a reference, it seemed, to allegations of accounting irregularities in Solidarity's Gdansk office.

Official spokesmen vigorously denied that Walesa had been arrested or even formally detained. Under Polish law, police are entitled to detain a suspect for up to 48 hours for questioning without placing legal charges against him.

The government is believed anxious not to rearrest Walesa since this would inevitably turn him into a martyr in the eyes of millions of Solidarity supporters. Instead, their tactic appears to be to subject him to petty legal harassment and reduce to a minimum his contacts with the outside world.

After dispersing the crowds near the railway station, riot police went into action briefly again following a memorial mass attended by more than 1,000 Solidarity supporters at St. Brigid's Church in the city center. They fired several concussion grenades and staged a quick charge to disperse a group of several hundred people who tried to march to the monument from the church.