Update postmeta after theme switch

I am going to guess that you have your code in the theme, probably functions.php. That code will only load when the theme is active, and after_switch_theme only runs after the theme change. There is no before_switch_theme that I am aware of.

You will need to have this code in a plugin or a mu-plugin file in order to have it work for all themes.

But don’t…

This kind of template highjacking is going to make whatever you are doing very unpopular. Not to mention that it is a very messy way to do things. You are altering database values that you are going to have to eventually clean up again.

Though it is not clear why you need to do this, or even exactly what the end result is supposed to be, I am pretty sure that they right way to do it is with the template_include and/or template_redirect hooks.

For usage examples:

https://wordpress.stackexchange.com/search?q=user%3A21376+template_include
https://wordpress.stackexchange.com/search?q=user%3A21376+template_redirect