The renderer can do many fancy things, and even if you know one, you can’t be sure what the other will do. And this is not even your job as a mapper to define what is “correct”, because it is decision what and how do you want to show things, not the ultimate “correctness”.

For example underground map will most probably show tunnels on top, even if in reality they are not visible on the ground. But this is just an example, maps can be just very different.

In case of default style on OSM.org (osm-carto style, I co-develop) here is a part of how it determines the order of areas (however there is no “global” ordering there):

https://wiki.openstreetmap.org/wiki/Standard_tile_layer#Rendering_order