I hope this is not a duplicate. I'm wondering how in the world they know how many rooms are free at any point in time. I know for almost sure that not all hotels are giving them access to their databases.
This post on thecodist.com explains it very well.
It answers your question with:
This can range from a real-time connection to a full reservation system which is used by all the chain's properties all the way to a fax machine and a daily or even weekly update.
TL/DR: Almost all hotel management software packages provide channel partner (booing.com, Expedia, Hotels.com, etc.) integration (inventory, pricing, booking, etc.) out of the box.
Booking.com, and any other booking agent really, can receive inventory data directly from the reservation system or aggregator through a number of proprietary or common standards.
The feed is enabled through property management system the hotel uses. There are many of these products on the market from big names such as Oracle or smaller vendors focusing on smaller properties. Even the smallest properties only need an Internet connection to use a web based solution.
All of these offer connections to channel partners as part of the product so the hotelier doesn't really have to to anything. While it's technically not 'database access' partners are able to query the data of any participating property.
Keep in mind, hotel inventory doen't change that fast. When you see "Booked 10 times today!" that means 10 times over the next ~300 days for their entire inventory. So, this inventory isn't updated real-time, just regularly.