She does this because she is mad at him. She is mad at him because she feels like it is his fault that she got in trouble with her teacher, Miss Caroline, on the very first day of school.
Walter is poor and so he was not able to bring lunch. Scout tried to explain that to Miss Caroline when she kept asking Walter about it. That (along with Scout being able to read) made Miss Caroline angry and she hit Scout's hands with her ruler. It didn't hurt, but it humiliated Scout and so she wanted revenge.