The episode is "The Last Temptation of Krusty" (Season 9, Episode 15).
It parodies Planet of the Apes: Krusty performs in an ape-run futuristic park, with a Dr. Zaius-like character as the leader.