This question involves two related but distinct concepts: joint trials and grants of immunity. A “joint trial,” where two or more co-accused are tried together in the same court-martial, is generally disfavored in military practice and is very rare. Usually, each accused is tried separately. If a joint trial were to occur, one co-accused cannot be compelled to testify against the other because of their Fifth Amendment right against self-incrimination.
More commonly, the government will “sever” the cases and try each person separately. To obtain the testimony of one co-accused against the other, the government can offer that person a grant of “testimonial immunity.” This is a formal, written order from the convening authority, approved by the Department of Justice, which compels the co-accused to testify. In exchange, the grant of immunity promises that their own truthful testimony will not be used against them in any future criminal proceeding (except for perjury if they lie).
A military defense attorney representing the remaining accused will vigorously attack the credibility of the co-accused who is testifying under a grant of immunity. The attorney will argue to the panel members that this witness is a “bought and paid for” witness who has a powerful motive to lie. They will contend that the witness is only testifying to save their own skin and that their testimony is inherently unreliable and should be disregarded. This is a standard and effective way to impeach a co-accused accomplice witness.