Scout rubs Walter Cunningham's nose in the dirt because she thinks that it is his fault that she got in trouble with Miss Caroline, her first grade teacher.
After having already gotten off to a rocky start when Miss Caroline reprimanded her for being too advanced in reading (a skill which Miss Caroline attributed to the "inappropriate" and unskilled intervention of Atticus), Scout's situation only worsens when she attempts to rescue Walter from certain humiliation. Miss Caroline notices that Walter did not bring a lunch to school and insists that she will give him a quarter to purchase one as long as he pays her back the next day. Hearing this, Scout intervenes and explains that Walter is a "Cunningham," which means that he won't accept the quarter from Miss Caroline because he will not be able to pay it back; he is too poor to do so, just as he is too poor to bring a lunch.
Unfortunately for Scout, Miss Caroline is sick of her commentary; she punishes Scout my making her stand in the corner—an act of humiliation for the young girl. Thus, Scout gets even by catching Walter in the schoolyard and rubbing his nose in the dirt.