I'm still looking for an answer to this. This doesn't sound like a hardware problem - from posts all over the net, it sounds like it's done by "design" (for what reason, nobody seems to have an answer for)
I was really excited about carrying my Magic Keyboard 2 because I can shut it off while it's my laptop bag - now I'm not convinced this is the case (but I haven't done enough traveling to really know)
All I know if the Magic Keyboard 1 definitely drains while in a bag that I have to take out the batteries (and this is after holding down the power switch on the right)