John has felt a guilt that he was not "good" enough through the whole play. First he felt guilt for his affair with Abigail. It was a stain on his moral goodness. Then while he was in prison, he felt guilty because he wanted to confess and live. He did not want to die. However, while he could lie to save himself, he could not lie to hurt others. Furthermore, he felt the life he was saving would be worth nothing to him if his name and integrity were destroyed. So he decided to rescind his confession.
When John decides not to lie, even though he would die as a result, he finally acheives goodness in his own eyes. Without that "goodness" his life was not worth living, and to get that goodness he had to die. His wife, Elizabeth is the only one who understands his need here. When Hale begs her to get John to reconsider his decision, she replies "He have his goodness now. God forbid I take it from him."
Actually, he is telling the truth. He initially gave in to pressure and confessed. He knows that the persecution that plagued them was wrong, and he wouldn't name others to share in the blame.
But, in the end, he could not let it happen. His name and integrity are everything to him, and even though he will lose his life, he will be morally right.