Canon law does appear to anticipate such a scenario (emphasis added):
Can. 335 When the Roman See is vacant or entirely impeded, nothing is to be altered in the governance of the universal Church; the special laws issued for these circumstances, however, are to be observed.
If a Pope was suffering dementia to the point that he was incapable of functioning as head of the Church, the Roman See could indeed be considered “entirely impeded.” In such situations canon law says the Church is to follow special laws issued for that situation. The problem is that, as of now, there are no special laws for what to do in that situation. There are special laws for when the Roman See is vacant but not if it is entirely impeded from its function by physical/mental health. So, essentially, there is no way that a Pope can be removed from office.
That’s not to say that the current or a future Pope couldn’t set forth special laws to address such a situation but as of now that has not happened. No one else has the authority to make those laws or address the situation.
DISCLAIMER: Catholic Answers has turned over the archive to Catholic-Questions.org and no longer owns, manages, or moderates the forums. For additional apologetics resources please visit www.catholic.com.