Rambam: Geirushin (2:20): “If the law requires that a man should be compelled to divorce his wife and he refuses to do so, the Jewish court anywhere, at any time, should lash him until he says I am willing; then he should write the get, and it will be valid.....So too, if non-Jews flogged him, saying to him: 'Do what the Jews are telling you,' and if pressure is exerted on him by Jews through non-Jews until he gives his divorce, it is a valid get ..... Why is this get not nullified, seeing that he is compelled by non-Jews or by Jews? The rule concerning a person who has committed a misdeed under compulsion applies only to one who has been pressured to do a thing to which he is not biblically bound.
To carry out the instructions of the Beis Din to coerce someone to give his wife a bill of divorce, which is something he has to do willingly. And therefore, even if only after the coercing he says that he does want to give his wife a bill of divorce, the ‘Get’ is kosher considering that his true will is to fulfil that which it says in the Torah.
