The earliest recorded use of the name 'Muggins' to mean a simpleton was in 1855 and possibly a reference to a character of that name in a Surtees story called Handley Cross published in 1843. By the end of the 1850s, it had already been shortened to 'mug', which is the more common version nowadays.
I have no idea of the date of the song mentioned by Chadad above, but I suspect it came later. It was written by Charles Ridgwell, so there's a start-point if you want to do some research to establish when it was written.