Can I use any digital component to avoid 7805 killing my microcontroller directly when its ground is disconnected (hence 12v goes to uC directly)?
Simplest way is to add another regulator, but it has to be an LDO regulator, not a 7805. 

For example, the AP2210N-5.0TRG1 has only a few hundred mV drop at 100-200mA and can handle up to +15V in. It's advertised as being able to withstand negative inputs as well, but I don't see a specifically stated voltage limit on that. Be sure to use the recommended input/output capacitors or it can go unstable. 

If you do supply +12V the regulator will likely go into thermal limiting, which is not good for the part, but it will protect the chip it's connected to. 



That's to answer your question, but really you need to fix the problem at the source as DKNguyen says, for example, by soldering the 7805 into a bit of perf board so the GND pin is solidly connected.