The Salem of the play is a theocracy, which means that God is supposed to be the ultimate leader, arbiter, and judge. In practice, however, the town’s religious authorities do the governing. God needs men on earth to do his work of justice, and Hathorne, Danforth, Hale, and Parris are all part of that system. They believed that God was speaking through the children to help them prosecute invisible, hidden crimes. The whole system gets turned upside down, and these men of experience and education are completely dependent on the assumption that the children were telling the truth and really did see what they claim to. In Salem during the witch trials, to be accused was to be guilty. To be guilty meant death. And the only way to avoid death was to confess. Though confessing was a way to bring those who strayed back into the fold, in this case it meant a lot of innocent people had to lie in order to keep their lives. Strange sort of justice.
Only those characters who have fallen and admit to committing grave errors possess anything close to a sense of justice.
In a play that seems hostile to religion, the ending is especially ironic. John Proctor receives no justice on earth, so the only way that we can think he receives justice would be in some other realm.