When Maria, in the drunk scene, comes up with the idea to make a plot against Malvolio, she tells Sirs Toby and Andrew that she will hide them somewhere where they can watch Malvolio letter, and, she adds, "let the fool make a third". Feste, however, does not actually appear as part of the threesome who watches Malvolio read his letter.
Some scholars think that Feste and Fabian (who does appear alongside Sirs Toby and Andrew) were the same actor, doubling up parts. Some think that Fabian is really supposed to be the same person as Feste (though the last scene of the play somewhat disproves this, as they appear on stage at the same time.
So - point is - Feste's role in the gulling of Malvolio is actually debated. What he does absolutely do, however, is dress up as the priest, Sir Topas, and goads Malvolio while Malvolio is imprisoned:
Nay, I prithee, put on this gown and this beard; make him believe thou art Sir Topas the curate. Do it quickly; I'll call Sir Toby the whilst.
Feste teases Malvolio, torments him, but eventually - after Toby has exited, agrees to get him light and paper. It's this letter Feste delivers to Olivia in the final scene which leads to Malvolio's release.
Toby, of course, wants out of the gulling by then, and needs Feste to engineer it:
I would we were well rid of this knavery. If he may be conveniently delivered, I would he were; for I am now so far in offence with my niece that I cannot pursue with any safety this sport to the upshot.
What role does Feste play then? Well, not a major one, really. He doesn't seem to be involved in the actual gulling, only in the exit of it. But that doesn't stop him from crowing over Malvolio at the very, very end, reminding him of his own curt rudeness on his first appearance in the play:
Why, ‘some are born great, some achieve greatness, and some have greatness thrown upon them.’ I was one, sir, in this interlude: one Sir Topas, sir; but that's all one. ‘By the Lord, fool, I am not mad.’ But do you remember? ‘Madam,
why laugh you at such a barren rascal? An you smile not, he's gagged:’ and thus the whirligig of time brings in his revenges.