I think the best way is hooking to the filter template_include
https://developer.wordpress.org/reference/hooks/template_include/
You’ll find some exmple at https://markjaquith.wordpress.com/2014/02/19/template_redirect-is-not-for-loading-templates/