What does "what for" mean and where did it come from?"

What for (Informal):

A scolding or strong reprimand: The teacher gave the tardy student what for.

Source: Collins Dictionary


My grandparents used the term.... it means, a reprimand, scolding, etc. "I'll give him a good "what for"!