How does WP determine the difference between a post and a page url

There is a priority in URL parsing, and page related parsing is the lowest priority, or you might say that page is the default parsing applied when nothing else works. In your example wordpress will first try to treat the URL as a post and if no matching post is found it will try to find a page matching the URL.