I disagree with the first response that Scout makes the men "realize what they're doing is wrong." I think this is rather, a classic case of "mob mentality."
Scout goes into great detail to describe what the men are wearing: long sleeved shirts despite the evening heat; those who were typically in hats wore no hat as evidenced by the tan line seen around their neck.
What Scout unwillingly accomplishes when she strikes up a casual conversation with Mr. Cunningham is she identifies him BY NAME. Suddenly he is no longer just a face in the mob. He is in individual. Granted, everyone knew everyone in the samll town of Maycomb, certainly Atticus himself recognized the majority of these men. But it wasn't until Scout identified him that he realized he was caught. Atticus was one man and it would have been his word against a mob. But the identification by a child is pretty hard to deny.
This scene is written to parallel real life activity of the KKK.
The men go to the jail to lynch Tom Robinson. Atticus tries to stop them. While he is talking to them, the kids show up. Scout starts talking to Mr. Walter Cunningham. When she talks to him, he sort of comes to his senses and realizes what they're doing is wrong. So the men leave.
Scout had no idea what she was doing when she made them leave. We know that because she says that she was just trying to talk politely to Mr. Cunningham which is what she has been taught to do when she sees someone she knows.
Atticus had said it was the polite thing to talk to people about
what they were interested in, not about what you were interested in.
Mr. Cunningham displayed no interest in his son, so I tackled his
entailment once more in a last-ditch effort to make him feel at home.