the flat top of a building or structure, above all the usable roof of a house
In the world of the Bible a roof was not a sloping cover you never touched. It was a flat, solid surface reached by an outside stair, and it doubled as extra living space. People slept there in the heat, spread crops to dry, kept watch, held private conversations, and gathered in crowds. Much of what happens on a roof in the Bible only makes sense once you picture this flat, walkable platform: Rahab hides the spies under drying flax on hers, David sees Bathsheba while strolling on his, and the law even requires a low wall around the edge so no one falls off.
The same word names the flat top surface of the altar of incense, the small gilded panel on top of the box that held the coals. It is the identical idea, a flat upper surface, applied to a piece of furniture instead of a house.
Because the roof was open and public, it also became a natural stage for worship, including forbidden worship. Prophets repeatedly picture people on their rooftops burning offerings to the stars and to foreign gods, and crowds standing on the housetops to wail in a public disaster.