The commas are unnecessary, but they're not grammatically incorrect. The meaning of the sentence is clear.
In days of olde, when English was just a lass, excessive commafication was commonplace. They told the reader where to pause when reading and speaking the written word, as these do.
Sometimes even today writers will use a comma to separate the subject from the predicate: it's rare, but not unheard of, but, like the elusive Sasquatch, even more rarely seen. These two commas turn the sentence into a "found poem" of sorts:
And those who were seen dancing [grammatical subject]
Were thought to be crazy [main passive voice verb phrase]
By those who could not hear the music [passive voice agent]
Commas cause contention. Some like 'em and some don't. The rules about their use are like overcooked spaghetti: even a tasty sauce can't make them palatable.