To the extent that an act is compelled by an outside source, the actor is not responsible for it:
Freedom is the power, rooted in reason and will, to act or not to act, to do this or that, and so to perform deliberate actions on one’s own responsibility.
(Catechism of the Catholic Church, paragraph 1731)
As long as freedom has not bound itself definitively to its ultimate good which is God, there is the possibility of choosing between good and evil, and thus of growing in perfection or of failing and sinning. This freedom characterizes properly human acts. It is the basis of praise or blame, merit or reproach.
(Catechism paragraph 1732; emphasis added)
Freedom makes man responsible for his acts to the extent that they are voluntary.
(Catechism paragraph 1734; emphasis added)
And most importantly for our purposes:
Freedom is exercised in relationships between human beings. Every human person, created in the image of God, has the natural right to be recognized as a free and responsible being. All owe to each other this duty of respect. The right to the exercise of freedom, especially in moral and religious matters, is an inalienable requirement of the dignity of the human person. This right must be recognized and protected by civil authority within the limits of the common good and public order.
(Catechism paragraph 1738)
The Church will recognize a distinction between an act which does good (to the receivers of the action) and an act which is good (that is, which allows one to evaluate the actor as a morally good person). Aquinas (Summa Theologica, First Part of the Second Part, Question 21, Article 2) states:
An action is said to deserve praise or blame, from its being imputed to the agent [that is, from the agent being responsible for it]: since to praise or to blame means nothing else than to impute to someone the malice or goodness of his action. Now an action is imputed to an agent, when it is in his power, so that he has dominion over it: because it is through his will that man has dominion over his actions, as was made clear above. Hence it follows that good or evil, in voluntary actions alone, renders them worthy of praise or blame.
So let's distinguish between what might be called useful actions (those which produce something good) and praiseworthy actions (those which allow us to call the actor "good"). Paragraph 1734 above is saying that one is not morally responsible for acts done involuntarily—acts you're forced into. In that sense, no forced actions are praiseworthy; you can't be a truly good person through being forced into it. (Neither, incidentally, can you be a truly evil person—everything depends on the extent to which you are forced into your actions.)
Thus, in the example you give in the SciFi question, Gandalf is producing "useful" actions—or rather forcing people into doing so—but he is not helping people be good people. And this, the Catechism says, is part of the responsibility of those who govern, at least to the extent that they must allow people to be free to choose to be good people. That's what paragraph 1738 (on the "right to the exercise of freedom") is saying. If Gandalf were to force his subjects to do good (i.e. to do useful things), he would be doing so at the cost of fundamentally injuring their human dignity—a grave sin.
Would this be worse than forcing them to do bad things? Perhaps not; in neither case would it reflect poorly on them, and in both cases it would be a grave sin on the ruler's part. (And forcing them to do bad things would, of course, result in objective evil being done.) But in no case would it ever be an acceptable course of action, or method of rulership.