In essence, Scout takes it upon herself to teach Miss Caroline about the citizens of Maycomb--in this case, Walter Cunningham. When Walter refuses the lunch money that Miss Caroline offers him and doesn't provide a reason for doing so, Scout replies, "He's a Cunningham." She feels this answer will provide Miss Caroline with enough information to know why Walter has refused her offer, since everyone in Maycomb knows that the Cunninghams won't accept anything they can't pay back.
However, Miss Caroline takes exception to Scout's behavior on the first day of school (Scout is also caught writing a letter to Dill and already knows how to write in cursive), and punishes Scout by hitting her hand with a ruler. As a result, Scout attacks Walter Cunningham because she feels it's Walter's fault that she has been reprimanded.