While going through the Cipher lab I healed my Pokémon just inside the door next to the PC, after using that PC to switch my Pokémon around, however I kept ending up back at the HQ lab whenever I whited out.
Obviously it isn't just the last place you healed.
Not true, all through the Cipher Lab, whenever I whited out I ended up in the HQ lab.
Then when I lost to Lovrina I ended up in the entrance of the Cipher Lab...
No, that is not true either. It is different for different locations. In most battles, it is the HQ Lab, some it does not matter if you win or lose, you just continue either way, and some (like w/ Greevil) it takes you back to a recent PC. But any way, you still lose the shadow. Hope that helps.