Its not as far as i know. Its based on a true story about a girl named Mary Sawyer who took her pet lamb to school with her one day. A visitor saw it there and wrote the poem. If someone told you its about the devil then they have a BIG imagination and might be crazy.
A lot if old nersery rhymes were written in England and were political in nature: like our political cartoons of today-only poetry! Mary was the Queen! Their meaning have faded over time, But they were political jabs at the Rulers of the day! Mistress Mary, quite contrary.... Humpty dumpty ..... All the kings horses.... ! See?