Following Johnny's death, Ponyboy begins to imagine that his friend is not dead in an attempt to avoid confronting the tragic situation. Pony also begins to insist that he killed Bob Sheldon. Ponyboy's insistence that Johnny is still alive and his purposeful admittance that he is responsible for Bob's death is Pony's way of avoiding the harsh reality. Ponyboy is essentially repressing the traumatic experiences, which is a natural psychological defense mechanism. It can also be argued that Ponyboy is suffering from Post-Traumatic Stress Disorder (PTSD). Pony's forceful delusion allows him to forget the traumatic experiences, which gives him a temporary sense of relief. The impact of Johnny's death on Pony's mental health is also the reason that Pony is not asked any questions regarding the murder of Bob Sheldon during the trial. Later on in novel, Ponyboy accepts the reality of the situation and uses writing as a therapeutic way to recover.
Like many people who have lived through a traumatic experience, it is possible that Ponyboy is suffering from denial. He refuses to beleive that Johnny has died. He even becomes angry with Randy when he visits to give his condolences.
We could probably infer that Ponyboy's refusing to beleive Johnny was dead was his not wanting to cope with the death of yet another loved one. Even after Johnny's death, Ponyboy is still compelled to protect Johnny, just as he did when Johnny was alive. This is why he tells Randy his intentions of telling the judge that he is the one responsible for Bob's death.