We say 'The book is on the bookshelf' because, if you imagine what this looks like, we can see the book, and we can see the shelf beneath it. It's the same as saying 'The cup is on the table' or 'The box is on the floor'. Bookshelves, tables and floors are flat surfaces, and you put things 'on' these surfaces.
By contrast, 'in' means 'inside'. For example, the cake is in the oven. The clothes are in the wardrobe. The money is in the wallet.