This only happens when in-game, and in specific games. During the menu it's fine, and in Days of Ruin it's also fine. Just about anywhere else, my (3)DS will rapidly toggle its sleep mode while closed.
Is it a bizarre antipiracy thing? A bug with the firmware? A problem with my cartridge itself?