According to the Codex docs, wordpress uses the query string and the template hierarchy to determine which template to use for a certain page.
First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested. Templates are then chosen — and web page content is generated — in the order suggested by the WordPress Template hierarchy...
However, using Dashboard settings, you can hand pick templates for pages:
So, in this case, how does the Wordpress engine determine this, and where is the information stored?