A foil is a pair of characters that compliment and contrast with each other in ways that deepen the story. Poe was very fond of this device, and it shows up in many, if not all of his stories, most notably, "William Wilson."
In “The Cask,” we find a classic foil in Fortunato and Montresor. It’s classic because they change places by the end of the story. There is a reversal.
At the beginning of the story, Fortunato is the epitome of freedom – he’s reveling in the spirit of the carnival. Montresor, on the other hand, is trapped by his desire for revenge. So he snares Fortunato with something Fortunato thinks will give him even more freedom: the Amontillado. What Fortunato thinks will free him, traps him, while simultaneously freeing Montresor − from his desire for revenge. By the end of the story, Montresor is free and Fortunato has been dead for 50 years, trapped in Montresor's catacomb.
But is Montresor really free once he’s killed Fortunato? You argue that Montresor is now trapped by the memory of his horrific actions, which is why he's still talking about it 50 years later. In that case, Fortunato and Montresor still form a foil – but they are complimentary characters instead of contrasting ones. Both are free at the beginning of the story, and both are confined at the end.