Damn, I just experienced this with my Type Cover 2. I don't use it too frequently, but this was the first time it happened. I just restarted (instead of shutdown) when I removed the TC 2. Ironically, it occurred right after composing a lengthy rant about my other SP2 difficulties...
Your rants makes you unworthy of using the Surface Pro 2
just kidding, of course
In all seriousness, The TC2 cover does that if the contacts are dirty on both the keyboard or on the device itself, or if it is not properly connected.
It's definitely a short that makes the device turns off. I don't believe there is a possible fix other a redesign of the affected circuit area (or the entire board in the case of the Surface Pro 2 as things are so compact), to fix this.
As the Surface Pro 3 has done so, due to the new form factor, it is probably fixed on it, but time will tell (although they did redesign the system board from the Pro 1 to the Pro 2)
These are the little things that shows that Microsoft needs more experience, and only time will fix those. I can't wait for the SP4 or SP5, where things should be greatly polished. And the reason why I am not too mad about those little quirks, is that Microsoft does show time and time again with the Surface line that they aim at making it all perfect. They don't go like other OEMs, and just go "Oh well, too bad... live with the flaw in all of our products and products to come, until we see it actually affects sales or reach the media"
However, I think we can all agree that for a company that never done something like this before, its pretty darn impressive. Usually, it's a total disaster.
Anyway,
Make sure that the contacts are clean on both the keyboard and device. Use ~60% rubbing alcohol with a quality swab that doesn't leave cotton behind as you clean, and swamp all contacts, and on your way, make sure that the reset of the slot if clean.
That should fix your problem.
When the keyboard is attached, I did notice a wiggle of 1-2mm from left to right, but hard to slide, due to the strong magnets, but possible to do. It could be that this has happened to you, and that shorted the device.