Why does Proctor confess lechery? Why does he think Danforth and Hawthorne will believe his confession? Why don't they believe him?
Proctor thinks that the court will believe him, because he is such a respected member of the community and because he thinks that they are interested in getting to the bottom of how the whole witchcraft hysteria started. But by the time Elizabeth is arrested, the court has been condemning people to die, so they have established through their verdicts that people were witches even though there is no real proof, only the words of Abigail and the girls.
Abigail has a powerful hold on the court, the judges, who are making decisions about whether people are guilty of witchcraft based on her accusations. She is completely in charge in the court with her displays of possession, seeing birds flying up near the ceiling of the courtroom, acting like a spirit has taken over her body and is choking her, and she is also in complete control of the other girls actions, so they mimic her every move, very convincing to the court.
Out of desperation, Proctor tries to shake the court's faith in Abigail as a credible witness. Lechery is a crime, so it will get the court's attention, especially because Abigail, as a Puritan young woman would be demoralized and punished for committing such a sin, as would Proctor.
John's confession of lechery comes just as Abigail scolds Danforth about being very careful not to distrust her word. So he is very cautious about what he is willing to believe about her, she has thoroughly intimidated him.
"Abigail: Let you beware, Mr. Danforth. Think you to be so mighty that the power of Hell may not turn your wits? Beware of it." (Miller)
So when Proctor confesses to having an affair with Abigail in his own house with his wife present, the judges need to prove that he is telling the truth. Considering that Abigail says to Danforth after Proctor tells his story:
"Abigail: What look do you give me. I not have such looks." (Miller)
The court brings in Elizabeth Proctor to prove that her husband is telling the truth. They will ask her to verify his testimony, if she tells the same story as John then he is telling the truth, if not then he is lying in an attempt to smear Abigail's reputation.
The court does not believe Proctor because when Elizabeth comes in to testify, she is not allowed to look at her husband, cannot talk to him, so when asked to verify if he committed lechery with Abigail, she lies to save his reputation to protect his good name. The court then decides that Proctor is lying about the lechery.