I did not know this until a little bit ago. I read a tumblr thing and I decided to google it.
Apparently in the 1800s a little girl named Mary had a lamb for a pet. She took it to school one day bacause he brother suggested to. That day the class had a visitor. He came back the next day with the poem.