According to The Oxford Dictionary of Nursery Rhymes (1951), edited by Iona and Peter Opie, dogs actually were sometimes tried and "hanged" in the 18th century. Usually it was for harming human beings - not sparrows!

Thanks and Acknowledgements

This rhyme can be found in The Little Mother Goose (1912), illustrated by Jessie Willcox Smith. It can also be found in The Nursery Rhymes of England (1842) by James Orchard Halliwell.