Whenever Randy Adderson has a conversation with Ponyboy about the upcoming trial, Ponyboy mentions that he was the one who killed Bob Sheldon. Ponyboy believes that Johnny was innocent and takes the blame for murdering the Soc member. The reason Ponyboy insists that he was the one who stabbed Bob Sheldon is because he is both in a state of denial and is suffering from posttraumatic stress disorder. Ponyboy has just witnessed the deaths of his two close friends which is extremely traumatizing.
He is not thinking clearly and desperately wants to repress the memories of the tragic events. Ponyboy is also in a state of denial and does not want to accept Johnny's death. He is essentially tricking himself as a coping mechanism. Ponyboy eventually comes to terms with the tragic death of Johnny and accepts the reality of the rough situation.