"Tom the Piper's Son" is a nursery rhyme, with the first known version published about 1795 in a London chapbook. The titular Tom steals a pig, is beaten as punishment, and runs away crying.
There was another, longer poem about a Tom the Piper's Son, which dealt with him playing music wherever he went, but this is less known and has nothing to do with the more well-known version.
The Ballad Index's writeup mentions a Lincolnshire text:
Tom, Tom, the baker's son
stole a wig, and away he run;
The wig was eat, and Tom was beat,
And Tom went roaring down the street.
A wig was a kind of bun, explaining what it had to do with a baker's son, how a boy could carry it easily, and how it could be eaten. The notes suggest that this version is the original. It makes sense that someone could have heard the poem, thought of the other kind of wig, and corrected it to the more edible "pig."
So the "pig" and "piper" elements could be simple oral mutations picked up as different people recited it, although it's impossible to say. There are a couple of versions, however, that particularly piqued my interest.
Tom Thumb the piper's son,
Stole a pig, and away did run ;
The pig was eat, and Tom was beat,
Till he ran crying down the street.
(From Gammer Gurton's Garland (1810) p.35)
And yes, in that version, it's Tom Thumb. It doesn't take much to go from "Tom, Tom" to "Tom Thumb." "Tom, Tom" is a bit too repetitive. "Tom Thumb" has more of a natural rhythm, and "thumb" is closer to rhyming with "son," at least in my accent.
I find it interesting how these two seem to build in severity. The wig-and-baker version suggests a closer connection, perhaps that Tom was in a bakery run by his family, and that they punished him for his misbehavior. The pig-and-piper version gives more distance - Tom lacks even a faint claim to the pig. Thus the images in the shet music, with a policeman seizing Tom for his theft.
This trend goes even further in a more violent version from Grey County, Ontario, published in The Journal of American Folklore in 1917.
Tom Thumb, the piper's son,
Stole a goose and away he run;
The goose got caught, and he was shot,
And that was the end of the piper's son.
This website is based on my research into folklore.