It's worth noting that film/game ratings systems (at least in the US, maybe not the case in countries like Germany and Australia) aren't "official." They were agreed upon by the major players of their respective industries. This kind of consensus was only possible because up until fairly recently (read: the internet), most movie/game production and distro was heavily centralized. They tend to be made by large teams and tend to be financed by industry backers during their production. Nothing's stopping anyone from making and releasing a movie/game on their own without an MPAA/ESRB rating. But getting distributed offline is very difficult, though this is beginning to matter less and less.
Books, specifically first drafts of novel-length fiction, on the other hand, frequently begin as the projects of one person. They write the whole book and shop it around to publishers (often through an agent), and then the process begins with editing, promotion, what have you. All in all, the publishing industry is much more decentralized and tends to be much better for content creators than the film/game industries because authors have much more control over their work. But anyway, getting off topic...
A big part of why movies/games have rating systems while books don't is the newness of those mediums. Moral panics about movies/games centered around how those mediums as a whole were *~*~corrupting the youth*~*~. No one could make this argument against books as a whole (lol), so book censorship by the government has always been on a per-title basis (Ulysses and Tropic of Cancer, eg.) However, there was a very real threat that the government would censor or ban movies/games as a whole, so the industries took steps to prevent this.
With movies, SCOTUS ruled in 1915 that movies were not protected speech under the First Amendment. As they got bawdier following the end of WWI, Middle America started losing its shit at how they reflected urban coastal sensibilities (surprisingly modern, especially wrt sexuality) and the industry implemented the Hays Code, self-censoring to prevent nigh-inevitable draconian laws. In the 50s, SCOTUS reversed its ruling and declared movies protected speech. The MPAA ratings in the 60s were a compromise to allow New Hollywood to do its thing without another public backlash.
Game ratings followed kind of a similar trajectory. Games had not yet been ruled protected speech, and in the 90s, a few senators basically said, "Yo, make a rating system like movies have or we will fuck your shit up." So again, it came about because popular perception was that the medium as a whole was potentially dangerous. But, again, games are now protected.
Part of me wonder how long it can last, though. Both the ESRB and MPAA have become rather reactionary, especially wrt sexuality. They were rather ahead of American culture when they came out. But nowadays they are decidedly behind it, reflecting the sensibilities of old straight white men. I dunno. The ratings are still essential for getting into "mass-market" movie theaters, passing console cert, and getting into stores, (and Valve/Apple don't require them but self-censor their platforms just as harshly), but it's hard to see how the current standards could be maintained without some sort of backlash in the future, especially as independent distro becomes more viable. It's interesting to think about!