If the selection of a Popoe reflects God’s will then that is the same as appointing, just using a particular means to accomplish it.
You’re leaving out the free will of man here in a big way. God does not will that people, including Popes, commit sins. That’s the person’s own choice. It’s also the person’s own choice whether he wants to immediately repent from his committed sin and try not to sin going forward, or alternatively just persists in some ongoing pattern of bad, unrepented sin.
A Pope, once reigning, has the same free will as you or me - the same free will that all humans have. The Pope can choose to act according to God’s commandments, or he can choose to sin. In some cases, particularly in the distant past, the Pope’s free will also might have been affected by some factor like mental illness, physical illness, coercion from some powerful ruler, etc.
There have been cases of Popes who took office and then likely committed grave sins, but there have also been cases of men who, upon becoming Pope, tried very hard to live good lives and not sin.
Popes are also picked by groups of men, not directly by God, and the choice also reflects the free will of the men doing the selection. They can choose a man they think is holy and will do a good job of leading the Church, or they can choose a man for some other reason like they want to increase their own power so they pick their friend even though they know he’s not holy. Let’s not forget that during a large part of Church history the Pope also had a lot of temporal and economic power, and no doubt this corrrupted the selection process in some cases.
In short: God doesn’t will people to sin. “Bad Popes” are the fruit of man’s sins. Not the will of God.
God has, however, protected his Church so that it survives “bad Popes”, although it might suffer some very bad effects as the consequences of sin.