Yes, throwing the switch inevitably leads to the death of an innocent person. (I’ll point out that performing the operation has the same consequence.) That, however, according to JPII, is insufficient to make the act immoral. The killing also has to be voluntary.
the direct and voluntary killing of an innocent human being is always gravely immoral.” JP II, VS (57)
This is rather different than the citation from 2258 :"…no one can, in any circumstance, claim for himself the right to destroy directly an innocent human being. " As I’ve said before, I don’t see any moral difference between throwing the switch and operating on the mother, nor is there anything in the definition I’ve used that makes a distinction: if the act of throwing the switch violates 2258, then so does operating on the mother. On the other hand, neither of the acts violates JPII’s definition.
Assuming 2258 and JPII are saying the same thing in different ways, which seems a very reasonable conclusion, then how do we reconcile them? I think JPII’s definition is the clearest, but if they mean the same thing then certainly committing an act which leads to an unwanted death hardly meets the criterion of having a right to kill when the death is desired. That is, your sequence fails at step 5. An act that leads to an unwanted outcome is morally different than the same act where the outcome is desired.