Custom Taxonomy rewrite rule causes 404 error on page or single post depending on if it’s set to “True” or “False”

As pointed in my comments, here are the issues with the /%location%/%postname%/ permalink structure:

  1. When the taxonomy’s URL rewriting is enabled, going to a Page like would result in a “page not found” error because WordPress sees the request as a “location” request, where in that example, WordPress would try to find a “location” (a term in that taxonomy) where the slug is page-slug.

  2. When the taxonomy’s URL rewriting is disabled, going to a Post like would result in the same “page not found” error because WordPress sees the request as a child Page request, where WordPress would try to find a Page where the slug is california/post-slug.

Now you asked in the comment:

Also I’m just curious, why is it that in Settings > Permalinks I
switch instead to %category%/%post-name%, issue does not exist? Will
wp not also see it as a “category” request – and will try to find a
“category” with the slug page-slug?

And the answer is, because WordPress automatically turns on “verbose page rules” (or technically, sets WP_Rewrite::$use_verbose_page_rules to true) if the permalink structure begins with %category% (or with a slash — /%category).

And what does that mean is, you can make your custom permalink structure works properly just like the %category/%post-name% structure, by enabling the verbose page rules.

How so?

Because that way, URLs matching a Page request would first be checked if it’s actually a Page.

Which means, in your case, for example would be checked if it is a Page before checking if it’s a “location”/term.

And here’s how can you enable the verbose page rules:

register_taxonomy( "location", array( "post", "blog" ), $args );
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true; // add this

I.e. Add the second line after calling register_taxonomy().

Or this works, too:

add_action( 'init', function(){
    global $wp_rewrite;
    $wp_rewrite->use_verbose_page_rules = true;
}, 1 );

Note: Be sure to flush the permalinks (just visit the Permalink Settings page) after you applied the above code changes.