If a Pope clearly realizes that he is no longer physically, psychologically, and spiritually capable of handling the duties of his office, then he has a right and, under some circumstances, also an obligation to resign.
Over the pope as expression of the binding claim of ecclesiastical authority, there stands one's own conscience which must be obeyed before all else, even if necessary against the requirement of ecclesiastical authority.