Pope John Paul II, speaking in Poland's industrial heartland, declared today that God, not the state, had given workers the right to form free trade unions.

For the first time on his trip, the pope referred directly to the Solidarity trade union, which was outlawed by Poland's Communist authorities after the imposition of martial law in December 1981. Previously he had used the word "solidarity" as a term for social unity. His words were greeted by prolonged applause and cheering from a crowd estimated by church officials at 1.5 million people in Katowice, capital of the coal-mining region of Silesia.

Earlier in the day, at a ceremony in the western city of Poznan in Poland's agricultural belt, the pontiff mentioned the name of Solidarity's companion organization, Rural Solidarity, which represented more than a million Polish farmers.

The pope's direct references to Solidarity, on the fifth day of his eight-day pilgrimage to his homeland, served to underline the outspokenness with which he has addressed sensitive political issues and the gulf that separates him from the government. In successive speeches, he has called on the government to reopen a dialogue with society and demanded respect for human rights and national sovereignty.

The concern with which the Communist authorities are following the trip was reflected in a statement by government spokesman Jerzy Urban Sunday that criticized the church for failing to prevent "political manifestations" from taking place during and after the religious ceremonies. Last night the pope attempted to calm down the crowds in Czestochowa by appealing to them to go home "in pious tranquility" following mass.

John Paul's choice of Katowice as the place to deliver his most detailed sermon yet on workers' rights was significant, as he was refused permission to visit Silesia during his first pilgrimage to Poland in June 1979. The Communist Party traditionally has attempted to keep the miners, who are regarded as "the aristocrats of the working class," insulated from religious influence.

Nearly four decades of Marxist indoctrination, however, did not prevent miners and their families from gathering on a vast, abandoned airfield outside Katowice to participate in perhaps the largest religious gathering ever seen in Silesia. A roar went up from the huge crowd as the pope's white helicopter descended out of the cloudy sky beside the 70-foot-high altar constructed for the occasion.

In pouring rain, they listened to him as he quoted the words of the late primate of Poland, Cardinal Stefan Wyszynski, on the "people's right to free association."

"This right is not given to us by the state," the pope declared. "The state has the obligation only to protect and guard it so that it is not violated. This right is given by the Creator, who made man as a social being."

At this point, the pilgrims, many of whom had belonged to Solidarity during its 16-month existence and are now refusing to join new officially sanctioned trade unions, burst into loud clapping. There were repeated chants of "Long live the pope" that ended only when John Paul said: "I tell you the pope is still living and wants to go on delivering his speech."

Together with other major cities, Katowice became a Solidarity stronghold following the workers' rebellion of August 1980, which ended with the government agreeing to recognize independent trade unions. Resistance to the imposition of martial law was stronger and more bitter here than in any other region of the country, with miners occupying their pits and physically defending themselves from attack by riot police.

Among the huge crowd was a delegation from the Wujek pit, where at least nine miners were killed three days after Gen. Wojciech Jaruzelski's military takeover when police stormed their mine.

The pope was applauded when he referred to the deaths by calling on the crowd to remember "all those who lost their lives in the recent tragic events" as well as victims of accidents at work.

During the past 18 months, the authorities have managed to tighten their grip on Silesia by a combination of tough security measures and offering the miners more privileges and higher pay than other workers. Silesia is the one important region of the country where there has been little evidence of underground activity.

Today's security measures in Katowice were much tighter than at any other stop on the pope's eight-city itinerary. Pilgrims walking toward the airfield were stopped and searched by police who confiscated banners and placards, even of a purely religious nature.

At a morning mass in Poznan, the pope paid tribute to the scores of workers who lost their lives and to the hundreds who were wounded in a bloody clash there with police in 1956.

Referring to a monument to the dead and wounded erected during the Solidarity period, John Paul II said: "This work is venerated by the society of Poznan and by Wielkopolska the name of the Poznan region . Therefore I also wish to kneel in my spirit in this place and pay homage."

Although crushed by the authorities, the Poznan outburst 27 years ago this month contributed to the toppling of Poland's Stalinist regime and ushered in a short-lived period of very limited reform. It was the first of Poland's periodic major worker uprisings.

Church officials originally proposed that the pope drive by the monument during his visit to Poznan. But this was rejected by Communist authorities. The pope's three-mile motorcade, from the meadow where a crowd of pilgrims estimated by church officials at 1 million gathered for the papal mass, to the cathedral he also visited today, passed far wide of the memorial in the city's center.

Crowds of people milled around the monument during the day, some holding illegal Solidarity banners. A squad of militarized police, or Zomos, confiscated a Polish flag that had the word Solidarity emblazoned on it and detained one man wearing a Solidarity T-shirt as the crowd jeered.

The pope devoted a major part of his homily in Poznan to farmers, describing them as strong defenders of fundamental rights, as people who have retained their national spirit through tough times.

A main feature of the Poznan service was the beatification of Mother Ursula Ledochowska, who founded a congregation of Ursuline Sisters in Poznan in 1920.

The pontiff only hinted at Mother Ledochowska's underground efforts in Russia to educate Catholic girls, saying she was forced to leave Russia in 1914.