John Proctor decides to confess his adultery with Abigail Williams to prove to the court that she has a motive for wanting to accuse Elizabeth Proctor of witchcraft. Proctor wants to make very clear to the court that Abigail's desire to get rid of his wife is what has driven her to accuse Elizabeth and others of witchcraft.
Another reason that Proctor decides to confess is because he thinks that by bring the light of truth into the court with the hope that his startling confession, which is a charge that will jail him, will jolt the judges back to reality and stop the hysteria as it relates to the witch trials.
Another reason that Proctor decides to confess is to discredit Abigail in the eyes of the court. Once Proctor brings the information to light about his affair with Abigail, a violation of the Puritan religious code of behavior, the judges look at her differently.
"A man may think God sleeps, but God sees everything, I know it now. I beg you, sir, I beg you—see her what she is. . . . She thinks to dance with me on my wife’s grave! And well she might, for I thought of her softly. God help me, I lusted, and there is a promise in such sweat. But it is a whore’s vengeance." (Miller)
An unmarried woman having an adulterous affair with a married man is a big no no. She would definitely lose credibility in the eyes of the judges and they would question her truthfulness after such a discovery.
"His determination to expose Abigail's false accusations eventually leads him to admit his own adultery to the court. He is at his most self-aware in his final speech when he realizes the importance of maintaining his integrity."
This does actually happen to Abigail that is why she runs away, because she realizes that she no longer has the power to control the judges in the court and, that Proctor is lost to her forever.