Poland's military government today announced the closing of all internment camps and said that it would free all of the approximately 200 persons held in them except for seven prominent leaders of the outlawed Solidarity trade union.

An official announcement said that the status of the Solidarity officials was being changed from internment to formal arrest.

The legal institution of internment without trial is to be abolished once martial law is formally "suspended" at the end of the year. A legal adviser to Solidarity, however, estimated recently that between 3,000 and 5,000 "political prisoners" will remain in jail either awaiting trial or serving prison sentences for martial-law infringements.

Over 10,000 people, mainly union activists, are officially said to have spent time in the internment camps since the imposition of martial law just over a year ago.

Some police harassment against Solidarity members and people formerly interned is expected to continue, including pressure to emigrate. Underground Solidarity bulletins have reported that, over the past few months, hundreds of union activists have been drafted into special "penal battalions" in at least 10 centers.

The reports have been denied by official spokesmen but are taken seriously by Roman Catholic Church officials.

Western analysts interpreted the decision to arrest the seven interned prisoners as a sign that, despite its aura of self-confidence, the government does not yet feel sure of its political grip over the country.

The Solidarity underground has suffered several major setbacks recently but still retains the confidence of many workers. Underground publications continue to circulate widely in spite of numerous police raids on illegal printing presses.

It is possible that the former Solidarity leaders could be put on trial alongside five political dissidents from the Social Self-Defense Committee (KOR) who were arrested earlier this year. The dissidents, all formerly interned, were charged with attempting to "overthrow the state by force."

The former Solidarity officials understood to be released today include Bronislaw Geremek, 50, a medieval historian who was personal adviser to union leader Lech Walesa; Tadeusz Mazowiecki, 55, a Catholic intellectual who edited the weekly Solidarity newspaper; and Janusz Onyszkiewicz, 45, the union's former press spokesman.

The seven who were arrested included Walesa's three rivals for the post of union chairman at the Solidarity congress in October 1981: Andrzej Gwiazda, 48; Marian Jurczyk, 48; and Jan Rulewski, 38. Gwiazda was one of the original leaders of the strike committee in Gdansk in August 1980 that resulted in the rise of Solidarity. Jurczyk and Rulewski headed the union's powerful Szczecin and Bydgoszcz chapters respectively. All three were considered more militant than Walesa.

Others arrested were:

* Seweryn Jaworski, 51, the Solidarity leader at the Warsaw steel mill and deputy to Zbigniew Bujak, the head of the union's Warsaw branch, who is now in hiding.

* Karol Modzelewski, 45, a union official from Wroclaw. One of Poland's leading dissidents, Modzelewski is credited with thinking up the name "Solidarity." He was a major contributor to union strategy.

* Grzegorz Palka, 32, Solidarity leader in Lodz and the union's expert on the economy and workers' self-management.

* Andrzej Rozplochowski, 32, Solidarity leader at the giant Katowice steel mill in Silesia. He was involved in a major conflict with the Communist authorities just before the military crackdown when his union branch attempted to replace the plant manager.

Contacted by telephone in Gdansk, Walesa said that he was "happy most of the internees have been released but sad that some of them had to remain in prison." He said the fact that three of those arrested had been his rival candidates for union leader was "a dirty trick" aimed partly against him.

"This is why I will fight with all my strength for their release," he said.

Onyszkiewicz, who was released from Bialoleka internment camp near Warsaw, said his pleasure at being freed was tinged with sadness. He said that his cellmate, Karol Modzelewski, had been taken away to prison only yesterday afternoon.

"The rest of us were only told today that we would be released. Right to the last moment, we didn't know what would happen to us," Onyszkiewicz said.

A government statement said the seven Solidarity officials had been arrested on the order of the chief military prosecutor "in connection with ongoing penal proceedings." It did not say what they would be charged with.

A propaganda campaign has begun in the official news media against what are described as the "extremists" in Solidarity. Men like Gwiazda, Jurczyk and Rulewski have been accused in the press of trying to take over power.

The closing of the internment camps -- of which there were originally 47 -- implies that discredited Communist Party leaders also have been released, although there has been no official announcement. When Gen. Wojciech Jaruzelski carried out his crackdown on Dec. 13, 1981, he ordered the arrest of several of his predecessors.

Former prominent officials interned at that time included Edward Gierek, the Communist Party leader of Poland during the 1970s, and two former prime ministers, Piotr Jaroszewicz and Edward Babiuch.

In what some observers saw as an attempt at balancing the arrests of the Solidarity activists, the government announced today that a parliamentary committee was examining the possibility of charging Jaroszewicz and three of his deputy prime ministers with "constitutional responsibility" for Poland's economic crisis.