From Light of the World, Benedict XVI’s 2010 interview with Peter Seewald:
Q: Have you thought of resigning?
A: When the danger is great one must not run away. For that reason, now  is certainly not the time to resign. Precisely at a time like this one must stand fast and endure the difficult situation. That is my view. One can resign at a peaceful moment or when one simply cannot go on. But one must not run away from the danger and say that someone else should do it.
Q: Is it possible then to imagine a situation in which you consider a resignation by the Pope appropriate?
A: Yes. If a Pope clearly recognizes that he is no longer physically, psychologically, and spiritually capable of handling the duties of his office, then he has the right and, under some circumstances, also an obligation to resign.