Granting immunity does not make it OK to compel testimony.
A prosecutor can not grant someone immunity and then force them to testify. And they don’t do that.
However, if the person agrees to testify, the prosecutor can grant them immunity.
The key is that it is not compelled testimony. No one is ever under threat of being prosecuted for not giving testimony against themselves. They are under threat of being prosecuted for other actions.
Guess the rules about inadmissibility of evidence don’t apply to testimony given under immunity. Very convenient.