It may seem counterintuitive to us, but books were not always shelved to show the spine.
Until the last century, books were a luxury that even most scholars could not afford, and before Gutenberg gave us the printing press in the 15th century, they were entirely hand-made. A single book was the product of countless hours of work by artisans and scribes (most of them monks). These manuscripts cost many times the average yearly wage of the typical worker. Therefore, few titles other than religious texts were created, and most of those were stored in monasteries or perhaps a wealthy citizen’s private collection.
To protect their investment, libraries (which were only accessible to a few; they were not open to the public) chained their books to the shelves or the lecterns, the medieval equivalent to the electronic security devices our libraries use today. The chains were connected to clasps which kept the books shut. It made sense to organize them with the clasps facing out so they could be pulled from the shelf.
Even this was a new development, though. Prior to this somewhat familiar placement, books were set horizontally on shelves or stacked out of sight, a natural progression from the days when the written word was recorded on scrolls.
The advent of “fore-edges out” shelving meant great attention was sometimes spent on aesthetics, like Odorico Pillone’s gorgeous (and extremely valuable) collection, commissioned in the 16th century. This type of artwork wasn’t the norm though. Most only had the title, perhaps the year, written onto the edge, if anything.
The practice of fore-edge painting continued, albeit rarely, into the 19th and 20th centuries.
More commonly, there was a lot of gilt and sometimes colored edging, even long after books and bookcases were designed to showcase decorative spines. Probably because, well, it just looks beautiful. And was not nearly as time consuming as intricate paintings.
The days of clasps and fore-edge shelving are long behind us. But of course we are still fascinated by the lure of these mysterious chained tomes of long ago, as evidenced by their appearance in modern folklore.