Your question touches on a significant and often controversial aspect of modern urban design. To address it directly: many public benches are intentionally designed with features that make lying down uncomfortable or impossible. This is not a "feature" offered in a traditional service sense, but a deliberate design strategy implemented by city planners and architects.
You'll notice many benches now have individual armrests dividing the seating space, slanted surfaces, or segmented seats. These elements effectively discourage people from stretching out to sleep. The primary stated goal is to maintain benches for their intended purpose—short-term sitting for the public—and to ensure accessibility for all users. Proponents argue it prevents benches from being monopolized for sleeping, which can deter other citizens from using them and sometimes raises concerns about hygiene and perceived safety in the area.
However, this practice, often called "hostile," "defensive," or "anti-homeless" architecture, is the subject of intense ethical debate. Critics argue that it criminalizes poverty and homelessness by making basic rest in public spaces physically arduous, instead of addressing the root social causes. It's a design solution to a complex human problem.
So, to answer your question: the prevention is achieved through specific design modifications. While it is a feature of the physical bench itself, it represents a broader, often contentious, policy choice about how we manage and share our public spaces. The debate continues on whether this is a necessary tool for urban management or an inhumane design trend that excludes the most vulnerable.