Libraries can charge for certain things. Though a hold was put on during the lockdowns, mine charge for reserving books. They also charge for printing, inter-library loans, and some other services and run events that can be charged for.
Even if we moved more things to digital, it wouldn't take away the need for physical buildings since quite a few of the licenses libraries have - such as for journals - are only valid if you're on library premises (unless we're going to encourage further academic pirating), and as others said, many libraries house multiple purposes. They're also a lifeline to some people.
In my city, there are technically 14 libraries if we look at a map. However, only four of those plus the Local Studies library are actually still run by the council. The others are "community managed". They all have very limited opening hours as the funding for it is pretty shite compared to costs.
In the same area, we currently have 2 council leisure centres, though only one of them has pools if we're discussing swimming. The one with the pool is pretty much the only place in the city that I know of that has a fully accessible pool including equipment for those with significant mobility disabilities to be in the pool safely. There are a couple of other places that were previously council that have very occasional public swimming, but they all charge in part because the funding for it is pretty shite compared to costs.
I don't really see a need to put them against each other in usefulness, but yes, it comes down to political will and financial limits. What we see if barely a fraction of what's going on and the costs involved.