The incident occurs at the beginning of chapter three. Scout has had a bad first day at school, starting with Miss Caroline criticizing her father for helping her read. Scout was offended by this criticism and was quite upset about it. Jem's attempt at making her happy during their break didn't succeed much. The second incident happened when she started writing a note and Miss Caroline told her to stop, repeating her original injunction that Atticus should not teach her.
Miss Caroline is clearly annoyed with Scout, and when Walter Cunningham refused her generosity when she offered him money to buy lunch since he did not have any, Scout attempted to explain the Cunningham tradition of not accepting anything if they could not pay it back. Miss Cunningham had, by this time, obviously had enough of Scout and decided to punish her. She gave her six pats on the hand with her ruler and sent her to stand in the corner.
Scout, when second break came, was obviously upset that her defense of Walter Cunningham had culminated in the punishment she had been administered. This was, evidently, the cherry on top and she had to vent her frustration. She therefore held the innocent boy responsible for the suffering she had experienced and wanted vengeance. It is for this reason that she decided to rub "his nose in the dirt." When Jem intervened and stopped her bullying, she told him that Walter had made her "start off on the wrong foot."
Jem later magnanimously invites Walter over to their house for dinner, probably to make up for Scout's unfair abuse.