Not exactly sure what your settings in LB look like or which tab you have the AHK pasted but below is what you should have set up.
In LB bind your button(s) to close a game to the "Exit" option. In BB bind it to the "Close Active Window" option.
Make sure the AHK you are suing is in the "Running Script" tab in the emulator set-up in LB.
If still no luck try the script below instead.
ESC::
{
SetTitleMatchMode, 2
WinWaitActive, Cemu
WinClose
}