Obvious answer is that they lie there in wait for helpless treasure hunter victims.

It could also be:

- They are placed in there by whoever put the item as a test

- Someone trapped them in there to save themselves.

- Monsters need some place to sleep. Running arround looting treasure chests is just like running into peoples homes and jacking their items. Of course they would be upset when you open it up waking them up in your attempted robbery.

And we all know inventory space is magical, so a treasure chest would assumedly have the same magical storage properties.