Yes that is exactly the case. Often judges do order witnesses who express reluctance to testify into custody so that they can be sure that they will show up for the trial.
Yes, judges and lawyers for both parties in a case can legally compel witnesses to show up and testify, but doing so tends to damage the credibility of the witness, which can be fatal for their testimony.
Its also used to hold political prisoners the government doesn't like in order to punish them.