Homer goes to Circuit Circus to buy a camera battery, but winds up purchasing a TiVo because the batteries are free with the purchase of a TiVo. The family enjoys using the TiVo to watch TV without the commercials, especially Marge, who happily skips over them. Late one night, Marge sees Keith Olbermann on the TV screen accusing her of not watching the commercials that pay for the TV shows, calling her "The Worst Person in The World", and convinces her to watch them. One such ad is for a new rib restaurant called Wes Doobner's World Famous Family Style Rib Huts, owned by a cowboy named Wes Doobner. The restaurant is perfectly suited to each member of the family, and they decide to visit it for its grand opening.
When they arrive they find the building deserted, and Wes Doobner door locks isnide. When he speaks, since Lisa recognizes his voice and realizes that "Wes Doobner's World Famous Family Style Rib Huts" is an anagram of "Sideshow Bob's World Famous Family Style Return". And Mr. Doobner unmasks himself as Sideshow Bob. After tying up the Simpsons, Bob shows them a slideshow of how he got to Springfield after Krusty prevented Bob from killing the Simpsons in Italy, built the restaurant, and produced the commercial. Sideshow Bob then reveals a large pile of TNT, with which he will kill them, using a laptop with a defective battery (which will overheat and explode) as a detonator. While gloating, Bob incorrectly quotes a phrase from Macbeth and Lisa corrects him. He tries to look up the correct phrase on English Wikipedia, but the laptop explodes in Bob's hands. He is then arrested and taken to court.
During Bob's trial, Bob's father, Dr. Robert Terwilliger Sr., is brought to testify. He explains Bob has a rare heart condition, and also suggests that Sideshow Bob is insane because of his long-standing feud with Bart. Sideshow Bob then asks if anyone was tormented by Bart's pranks, to which everyone responds positively. This convinces Springfield that in the long-run Bart is ultimately to blame, and they turn against him. As Bart pleads his innocence, Bob takes out a vial labeled nitroglycerin, which Bart snatches and throws out the window, thinking it was an explosive. The vial was actually Bob's heart medication, and he collapses on the floor, unconscious, and is pronounced dead.
Bob's entire family attends the funeral: His mother, Dame Judith Underdunk, a well-known Shakespearean actress; his father; his brother Cecil, who was let out of jail for the occasion; his wife Francesca, who is now a widow; and his son, Gino. Many of the regular Springfielders also attend the funeral. Feeling slightly guilty, Bart speaks to Cecil and decides to go to the Springfield Funeral Home to make peace with Bob's corpse before it is cremated; however, Bob rises out of the coffin, very much alive, and traps Bart in the coffin to be incinerated, all the while gloating over his old foe. Back at home, a request to relax at the Simpson house by Milhouse makes Lisa realize that everything was an elaborate plot put together by Bob's entire family, explaining that because of his mother, Bob would have known Shakespeare too well to have misquoted him accidentally and that he must have done so intentionally in order to get caught and go to trial, where he was put in a temporary deathlike state with a special drug injection by his father (Cecil helped by playing to Bart's guilty conscience and encouraging him to visit the corpse, though Bob refuses to express any appreciation for his brother's efforts, snidely remarking, "Yes, and Hamlet is all about Laertes!"). The Simpsons race to the funeral parlor (but waste time driving in circles around the building for ten minutes for Lisa to finish her explanation) and narrowly save Bart from being burned alive by blinding Bob with unclaimed ashes.
The police then arrive and arrest the Terwilligers. Defeated, Bob asks Lisa how she knew of his scheme, and Lisa explains that she was suspicious that Bob's coffin had extra room for his large feet, which the family would not have bothered to pay to have put in "for the comfort of a dead man". Bob and his family are sentenced to prison for 87 years and have to share a cell with Snake who constantly torments them.