It seems to depend on the shape of the shelf. If it's just one shelf hanging on the wall, it's more likely that you'd say på = on. But if it's for instance a bookshelf with many shelves and closed sides, it's more likely that you'd say i = in. It depends on whether you see something as "on top of" the shelf or "inside" it.
After reading a post linked in another comment section about the use of det when rhe subject is unknown, is there a particular reason den is used here?
I see a few others have asked but I don't really see a response. Is it that in this example case they are talking about a known object?