One might surmise that, when a book is published, it stays around more or less forever. This is only rarely true. In fact, the vast majority of my published work is out of print currently, and generally no longer available in any format.
There are many reasons for this. In several instances in my work, for example, the publisher I worked with produced licensed work based on other media, and that contract expired so they no longer have the rights to publish that material. In some cases the publisher(s) aren’t even allowed to sell their remaining stock of items based on that license. A great example of this is Margaret Weis Productions and both the Leverage and Firefly RPGs they published. I contributed material to books for both of those games, and when the license ran out, that was it. I believe they were able to sell of remaining stock, but the digital versions immediately went away. Interestingly, there is a situation where people can publish material linked to tabletop role-playing games through a Community Content program spearheaded by online RPG purveyor Drive Thru RPG.

Changing Breeds: Wild West Tales is an anthology of were-creature stories set in the wild west of the United States. I helped get this anthology published through that Community Content program. All of the authors technically own their own stories, though because the material is based on existing IP, any author wishing to republish their story elsewhere would need to take great pains to insure than no part of the IP remains in the re-purposed story. As long as the Community Content program remains active, the authors continue to receive royalties from sales. Sadly, part of the agreement is that Community Content material exists only digitally, though last I heard they are considering allowing print on demand on a test basis with select titles. Here’s a link to that anthology, currently available only as a PDF. https://www.drivethrurpg.com/en/product/331555/changing-breeds-wild-west-tales-anthology
Is the ephemeral nature of publishing less true in the mainstream fiction world? Well, not really. A publisher might decide that any given book is no longer generating enough revenue to justify keeping it in print. Also, publishers—especially small presses—go out of business frequently. In some cases authors can buy up a bunch of leftover stock, but who has the spare cash AND the extra space to keep cases of books lying around only to sell a handful of copies each year, if that many?
As far as rights reverting, it varies. For the RPG world, the vast majority of material is done as work-for-hire. That means you surrender all rights to what you’ve written on that project in exchange for the paycheck. Period. Doesn’t matter if the work is licensed or not, you don’t own it any more once they pay you for it. This is the standard for the RPG world; be extemely wary of any fiction publisher outside of tie-in material for existing IP who offers work-for-hire contracts for fiction.
Copyright laws in the US are tricky. In most cases of original fiction the rights revert to the author if the publisher ceases to do business, but everything depends on the contract you’ve signed, so BE SURE TO READ (AND UNDERSTAND) YOUR CONTRACT BEFORE SIGNING ANYTHING! More than a few publishers are predatory in nature, and will try to get away with whatever they can. This includes some HUGE household name companies for whom publishing is kind of a side-line.
I enjoy writing, but as with many things the business side can be frustrating, to say the least. With the number of people who read for pleasure diminishing almost daily, it’s more important than ever to support the authors whose work you enjoy. Even if you can’t afford to buy books regularly, please consider writing reviews (these can be brief: “I really enjoyed X by author Y” is sufficient!) and sharing your favorite authors’ promotional social media posts to help get the word out on their work.