Why does Ms. Caroline hit Scout with the ruler?
The short answer to this question is that Scout annoyed Miss Caroline. In chapter two, Scout succinctly says: "I knew I had annoyed Miss Caroline..."
The longer answer is that Scout did two things to catch the negative attention of Miss Caroline.
First, Scout told Miss Caroline that she knew how to read. When Miss Caroline said that Scout's father should not teach him to read (lest he teach her in an incorrect way), Scout said that he did not teach her to read. In fact, Scout said that she was born knowing how to read. When Miss Caroline begged to differ, Scout was insistent.
Second, during lunch, when Walter Cunningham did not have lunch, Miss Caroline was going to give him some money. Scout interjected and said that she should not, because the Cunninghams do not take money. This annoyed Miss Caroline again.
In the end, she was hit. Here is what Scout says:
Before the first morning was over, Miss Caroline Fisher, our teacher, hauled me up to the front of the room and patted the palm of my hand with a ruler, then made me stand in the corner until noon.