The Court has held that broad immunity for both the Government and military and civilian officials who injure military personnel or violate their constitutional rights is necessary to preserve military discipline and to prevent Federal courts from second-guessing command decisions.

Justice Scalia said that the allegations by former Sgt. James B. Stanley that the Army's LSD experiments had caused him to ''awake from sleep at night and, without reason, violently beat his wife and children,'' would entitle him to no compensation even if proved, because his injuries ''arise out of or are in the course of activity incident to service.''

In his dissent, Justice Brennan said: ''The Government of the United States treated thousands of its citizens as though they were laboratory animals, dosing them with this dangerous drug without their consent.''

He added that ''the Court disregards the commands of our Constitution, and bows instead to the purported requirements of a different master, 'Military Discipline.' '' If this were a correct reading of the Constitution, he concluded, ''soldiers ought not to be asked to defend a Constitution indifferent to their essential human dignity.''

His dissent was joined by Justice Thurgood Marshall and in part by Justice John Paul Stevens.

Justice Sandra Day O'Connor, in a separate dissent, said that the Government and its officials should be protected from lawsuits by military personnel, but said that ''conduct of the type alleged in this case is so far beyond the bounds of human decency'' that ''it simply cannot be considered a part of military discipline.''

Mr. Stanley's suit grew out of secret Army experiments at the Aberdeen Proving Grounds in Maryland, using enlisted men who had volunteered for what they had been told would be chemical warfare tests with gas masks and protective clothing.

The Army's human experimentation with LSD, or lysergic acid diethylamide, was part of a broader Government program in which the Central Intelligence Agency also participated.