I think that painting the edges of books served as protective function. Particularly with that stiff gold paint. When a book which has that golden coating is closed and packed into a bookshelf, the coating presents a surface that is likely harder to penetrate for pests like moths and worms. Possibly mould spores and such too.