The Duties of a Pope
Pope St. Pius X mentions his papal duties at the very beginning of his encyclical against Modernism, Pascendi Dominici gregis (1907):
The office [of the papacy] divinely committed to Us of feeding the Lord's flock* has especially this duty assigned to it by Christ, namely, to guard with the greatest vigilance the deposit of the faith delivered to the saints, rejecting the profane novelties of words and oppositions of knowledge falsely so called.
*cf. John 21:15-17, where Jesus tells St. Peter, the first Pope, to feed his flock (i.e., to give Christians the truths necessary for salvation).
St. Thomas Aquinas's commentary on John 21:15-17 overviews the duties of a pope. A pope is to feed the flock (i.e., all Christians) by:
teaching: "And I will give you shepherds after my own heart, who will feed you with knowledge and understanding" (Jer 3:15).
example: "Set the believers an example in speech and conduct, in love, in faith, in purity" (1 Tim 4:12); "Upon the mountain heights of Israel," that is, in the excellence of great men, "shall be their pasture" (Ez 34:14).
being offered temporal help: "Woe, shepherds of Israel who have been feeding yourselves! Should not shepherds feed the sheep?" (Ez 34:2).
So, a pope must teach (cf. the Great Commission, Mt. 28:19: "Going therefore, teach ye all nations"), sanctify, and rule (yes, even temporally; cf. Cdl. Manning's The Temporal Power of the Vicar of Christ).
The Council of Florence defined, and the First Vatican Council (Pastor Æternus cap. 4) reiterated, that
the Roman Pontiff is the true vicar of Christ, and the head of the whole Church, and the father and teacher of all Christians; and that to him in blessed Peter was delivered by our Lord Jesus Christ the full power of feeding, ruling, and governing the whole Church.
Vatican I called this the Roman Pontiff's "pastoral duty" or pastorale munus (ibid.).
Pope Benedict XIV wrote (Pastoralis Romani Pontificis):
the duties of his [i.e., of a Pope's] office, are principally and above all manifested in maintaining and conserving the unity and integrity of the Catholic faith, without which it is impossible to please God.
"Bad Popes"
Bad popes would be those who do not live up to their aforementioned duties.
Regarding "bad popes" and such bad "popes" that they are not even popes, see this article: