Books can be purchased at Adventure Traders, Construction Traders, Hive Traders, Trade Goods Traders in nearly all settlements, as well as from Wandering Caravans.
They can be looted frequently from Ancient Labs, Ancient Tech Lab, Burn's Tower, Dust King Tower, Lost Library, Post-Ancient Workshop, Spider Nests, and World's End. And infrequently from Dust Bandit Camps, Holy Mine Ruin, Suspicious Lab, Tiny Settlement. They can also often be found and stolen from inside houses throughout various towns. You need a total of 306 books to research everything.