Irony exists when what is expected and what occurs are in conflict with each other. As a literary device and a figure of speech, it highlights inconsistencies and is intended to draw attention, often in a humorous or marginally sarcastic way, to situations and actions which contradict their usual meaning. It gives an edge to the work in which it's being used to add depth to the reader's understanding.
"The Village Schoolmaster" is part of a larger poem by Oliver Goldsmith called The Deserted Village and read in isolation, it laments a time when the school is viable and not "behind a straggling fence." This sets the tone for the poem and is ironic because a school is a disciplined, organized environment and not one surrounded by an unkempt fence. The schoolmaster, at his peak, ran his "little" school. It sounds somewhat derogatory to call his school "little" and is ironic that, for him, his school would have been everything, where he was "skill'd to rule." Irony often exists in hyperbole and suggesting that he "rule[d]" overstates the schoolmaster's influence and again contradicts the use of the word "little," revealing the irony.
It seems that the image of the schoolmaster is one of a "severe" man but a man with "many a joke." The irony here is that the children laugh at his jokes and he thinks he is obviously funny but in reality they are scared of him because they laugh with "counterfeited glee."
The overemphasis on his knowledge is ironic and humorous because he is a schoolmaster so really should be knowledgeable anyway but as he is in a village, the suggestion is that the residents are perhaps not quite so learned and are "gazing rustics," simple people. This is almost sarcastic in its tone. The fact that the residents are in awe that "one small head could carry all he knew" continues the tone.
The narrator reminds the reader that, for all the schoolmaster's learning, he is no longer important. It is ironic that, having been such a prominent figure in the village, even standing up to the parson (the reverend), he is now forgotten.