For a long or overnight layover, the key question is whether leaving the airport counts as entering the country, and it almost always does. Stepping out to reach a hotel, even one across the road, means passing immigration, so you need either visa-free status, a visa, or a special transit permission. Sleeping airside in the transit area avoids the issue entirely if the airport allows overnight stays there.
The good news is that several countries offer exactly the tool you are describing: short-stay transit permits or transit-without-visa schemes that let connecting passengers leave the airport for a limited period, sometimes a day or two, sometimes longer. Conditions usually include a confirmed onward ticket to a third country and arrival at specific airports.
Some transit hotels sit inside the secure zone, which is worth checking before you assume you must exit. Confirm the current transit scheme rules on the immigration authority's official site, since eligibility often depends on nationality and exact routing.