The dictionary gives the first meaning of smart as the sensation of pain, it then gives smart as slang for intelligent.
The teachers gave lazy students blows to various parts of the anatomy. First their backsides smarted, then their brains learned how to avoid punishment, and the students then were "smart."