This is just a theory, so please don't dis me.
The "Purple Man" was a day shift employee at Freddy Fazbear's Pizzeria when he killed five children out of rage using the Golden Freddy costume as a disguise. Cause: annoying customer. After he was put behind bars for his crime, he broke out and went back to his former workplace to stuff the children's corpses in the animatronic suits. Knowing that he would be found eventually, he disguised himself as the marionette (ripping out the endoskeleton, which explains the random endoskeleton roaming the second game) and hiding in the music box. Not realizing beforehand that the music box did not open from the inside, he was trapped.
It had been days since he had accidentally locked himself in the box when he died, due to suffocation and starvation. The ghost of the Purple Man still lives in the marionette, but the body-purple due to suffocation- still murders children shamelessly.
Please tell me in the comments if there are any holes in this theory so I can improve it!
Thanks for reading!