Add sanity checks to `get_*_template()` functions to ensure that the return value of `get_queried_object()` is compatible with the assumed context.

Fixes #25291.
See #25282.


Built from https://develop.svn.wordpress.org/trunk@25386


git-svn-id: http://core.svn.wordpress.org/trunk@25325 1a063a9b-81f0-0310-95a4-ce76da25c4cd