A second bugging scandal in less than a month has rocked West Germany politics and may also jeopardize completion of the important and controversial trial of the Baadar-Meinhof terrorist gang that has been under way for 23 months.

The second bugging episode surfaced yesterday when the justice minister in the state where the accused terrorists are being tried acknowledged that he had authorized emplacement of secret listening devices in the prison cells of three of the alleged leaders of the gang.

Although defended on the groun that a new terrorist attack may have been in the offing to try to free the prisoners, the admission has once again raised questions about the reaction of security agencies to potential terrorist activities and about how much control the federal government has over these agencies.

The revelations brought renewed opposition party criticism today of the government of Chancellor Helmut Schmidt, which was badly embarrassed just two weeks ago when it was disclosed that the home of a promised nuclear scientist, Klaus Traube, had been bugged because he was suspected of having links to terrorists.

The disclosures led to hasty high-level meetings of all three major political parties here and caused Foreign Minister Hans-Dietrich Genscher - who heads the minority coalition party, the Free Democrats - to cut short a visit to Spain.

Although there have been many charges that both bugging actions were illegal and not properly authorized, both cases also came at sensitive times for West Germany, which had serious problems with terrorists a few years ago and which seems to have a special fear of them.

The bugging of the three Baader-Meinhof defendants, according to the justice officials, started on April 24, 1975, one day after West Germany terrorists attacked the West Germany embassy in Stockholm. The bugging was carried out for a total of 24 days, apparently off and on, and into 1976.

In Traube's case, although the bugging turned up no evidence against him, he acknowledged having known Hamss-Joachim Klein through a mutual friendship with a Frankfurt lawyer who defended radicals. Klein later was one of the gunmen who invaded the oil ministers meeting in Vienna in December, 1975.

Running through both cases is a thread that indicates neither Schmidt nor Federal Interior Minister Werner Mainnfer had prior knowledge of the bugging, especially of court defendants, even though the technical help of the federal security agencies was used to implant the devices.

Schmidts spokemsan Klaus Boelling, said today that the Chancellor and his office had been informed about the Baader-Meinhof bugging only in recent days. Maihofer was told last Saturday, he said.

Maihofer, who was severely embarrassed over the Traube affair because he is widely respected for his liberal views, said after that episode that it was the only bugging case he knew of.

The West German Law Association today condemned the prison bugging as a clear violation of the defendant's rights. The Baader-Meinhof trial began in May, 1975, but the defendants were held in a fortress-like maximum security prison outside Stuttgart for an unusual three years of pre-trial detention while the case against them was built.

The charges against them include bank robbery, murder and a half dozen bomb attacks, including the 1972 bombing of U.S. Army installations in which four GI's were killed and 14 others wounded.

The trial had been expected to end this spring, but it ran into trouble in January when the presiding judge was removed for prejudice against the defendants.

Now, in the aftermath of the bugging disclosure, the defendants' lawyers are demanding a new trial. They are boycotting the existing proceedings and the three prisoners - Andreas Baader, Jan-Carol Raspe and Gudrum Ensslin - are starting a hunger strike.

The other alleged gang leader, Ulrike Meinhof, hanged herself in her cell last May.