I don't know anything about linguistics so this is not an expert comment. I'm puzzled, too. I can only think of two senses of the word "word" that could apply here. There could be a third but it doesn't seem to apply here.
1) The number of words that would be counted by a computer is 56. The word "up" appears seven times and would count as seven.
2) The number of _unique_ words is smaller. There are only 29 unique words: again, and, down, duke, grand, had, half, he, hill, marched, men, neither, nor, of, old, only, ten, the, them, then, they, thousand, to, top, up, way, were, when, York. If this rhyme were the only piece of English someone knew, you would say they knew 29 English words.
I had thought there might be an issue of what it means to be "the same word." For example, the words "griffin" and "gryphon" would be counted by a computer as two different words--two different sequences of characters. But in fact they are two different acceptable spellings of the same word, with the same pronunciation.
On the other hand, in the sentence "I'll wait while you drink your drink," we might say that the two occurrence of "drink" are different words, because the first is a verb and the second is a noun, or we might say they are two different forms of the same word.
We might say in the sentence "the soldiers carried their arms in their arms," a computer would count "arms" as two different occurrence of the same word, but here they are "really" different words meaning "weapon" and "part of the body," that just happen to have the same spelling.
And my mother used to say things like "Oh, 'adamant' and 'diamond' are really the same word." She meant that they were etymologically derived from the same source, and had just somehow split into two slightly different spellings and pronunciations.
However, I do not see any of these puzzling situations in the nursery rhyme.