I can’t think of any possible way to achieve this. I don’t think Apple allows interactions with the home outside of shortcuts and the home app. I’m not sure scripts could trigger anything.
You may be able to use Automator to automate (heh) mouse movements in the home app and possibly achieve a workaround that way? But it wouldn’t be as seamless as you’re hoping for, and I’m not sure you could trigger it before/during/after pressing the lock key. Might have to be manually ran which defeats the point.