The Rambam (2:20) explains the mechanics of a forced gett is that:
לפיכך זה שהוא רוצה להיות מישראל ורוצה הוא לעשות כל מצות ולהתרחק מן העבירות יצרו הוא שתקפו, וכיון שהוכה עד שתשש יצרו ואמר רוצה אני כבר גירש לרצונו
This implies that only one who "wants to be part of klal yisroel" would be considered consent after being forced, but one who converts to christianity or islam and does not wish to be part of klal yisroel, cannot be forced even by a jewish beis din to give a gett. The Ohr Sameiach quotes the maharitatz who points this out and therefore rules that for a convert to another religion, a forced gett would be invalid, since it only works for one who wishes to remain part of klal yisroel. The Maharik suggests that under the circumstances of a convert maybe chazal use the mechanism of uprooting his kiddushin, but clearly that is a very difficult approach to accept. Therefore the Ohr Sameiach asks, Why is the "minhag" to force a convert to give a gett?
The Ohr Sameiach develops a complicated yet brilliant approach. When Beis din forces to fulfill a mitzvah, their power is limited to their ability to actually accomplish their goal. Meaning, if they would be certain somehow that this person will never consent and will give up his life to not perform a mitzvah, they would not have the right to force him (since the force is for the purpose of getting him to do the mitzvah, not as a punishment). Based on this we should never be able to force anyone, because anyone would tell you that they would ultimately not want to give the gett so that beis din will loose their ability to force, rather than his "rotzeh ani" qualifying as consent which empowers beis din to apply force! It is to answer this question that the Rambam has to explain that the inner will of every jew is to be part of klal yisroel and do mitzvos. Meaning, that as far as "consent" is concerned, the fact that he declares "rotzeh ani" in the end is all we care about since דברים שבלב אינם דברים. The only reason we need the logic of the inner ratzon is to serve Hashem is to explain why we have the right to whip him to begin with. And that is, we assume that the inner will of every jew (who wants to be a jew) is to serve Hashem, and give a gett when the din requires it. This inner ratzon is not needed to qualify as consent, rather is necessary to give the beis din the power to force to begin with. Now, this whole explanation is only necessary for one who want to be part of klal yisroel and is not a idolator because our ability to force him is only if we would be convinced that his inner will is to consent. Without that we have no right to consent based on the logic of forcing for an aseh. But one who is an idolator who we have the right to PUNISH and even kill for his aveira of idolatry, we don't need his ultimate consent to entitle us to whip him. We have a right to whip him even if we knew he would never consent, as a punishment for his aveira. Therefore, we don't need his inner ratzon to consent, we just need him to say "rotzeh ani" after suffering and that is sufficient to make the gett work. Based on this the Ohr sameiach is mechadesh that for a convert to christianity or islam, even if we force "shelo k'din", the gett should be valid because we don't need a heter to whip him.