Epicurus's old questions are yet unanswered.
Is he willing to prevent evil, but not able? then is he impotent. Is he able, but not willing? then is he malevolent. Is he both able and willing? whence then is evil?
[Hume, Dialogues Concerning Natural Religion, Part X.]
It has been noted by quite a few people before that this is not actually found in Epicurus; in fact, it is inconsistent with everything Epicurus actually says about the gods in the extant texts we have, such as the Letter to Menoeceus.
The origin of the trilemma seems ultimately to be Cicero, De natura deorum III, 39:
Either, therefore, God is ignorant of his powers, or is indifferent to human affairs, or is unable to judge what is best.
This is perhaps not surprising, given that Dialogues Concerning Natural Religion is very heavily influenced by De natura deorum. But noticeably, the trilemma in Hume is not exactly what you would expect from that in Cicero. It is serving different ends (which is perhaps not surprising), but, more importantly for assessing influence, in Cicero it is not treated as Epicurean; Cotta, the speaker, is an Academic skeptic, although he is speaking against Stoic ideas, having previously spoken against Epicurean ones. It's also very improbable that Hume, a close reader of Cicero writing in a dialogue heavily influenced by the very work in question, would have simply misremembered it and never caught it in the dialogue's extensive revision over time.
A very likely suggestion is that the original of Hume's trilemma is from Lactantius, De ira Dei XIII:
But if this account is true, which the Stoics were in no manner able to see, that argument also of Epicurus is done away. God, he says, either wishes to take away evils, and is unable; or He is able, and is unwilling; or He is neither willing nor able, or He is both willing and able. If He is willing and is unable, He is feeble, which is not in accordance with the character of God; if He is able and unwilling, He is envious, which is equally at variance with God; if He is neither willing nor able, He is both envious and feeble, and therefore not God; if He is both willing and able, which alone is suitable to God, from what source then are evils? Or why does He not remove them? I know that many of the philosophers, who defend providence, are accustomed to be disturbed by this argument, and are almost driven against their will to admit that God takes no interest in anything, which Epicurus especially aims at; but having examined the matter, we easily do away with this formidable argument.
In some sense, this just moves the puzzle back, since Lactantius was also a close reader of Cicero and is quite clearly following along with Cicero at this point in his work -- indeed, he just quoted Cicero a couple of chapters before. It seems likely that Lactantius is using 'Epicurus' as a representative name for Epicureans generally rather than as a strict historical matter, but if so, it isn't clear what he would have in mind. When he says 'Epicurus' he often really means Lucretius, but I don't think he's getting this argument in particular from Lucretius. It is sometimes suggested that the attribution arises through a (probable scribal) confusion between 'Epicurus' and 'Empiricus'; it is virtually impossible for this to be Lactantius's own confusion, so it would need to be in some source he was using, and we have no idea what that would be. It is true, though, that Sextus Empiricus has a very similar argument in Pyrrhōneioi hypotypōseis III, 3.
Hume almost certainly did not read Lactantius directly. Rather, he is getting Lactantius second-hand from Pierre Bayle, in particular, the article in Bayle's Dictionary on the Paulicians, which is, not surprisingly, on the problem of evil, and contains the passage from Lactantius in Note E.