This issue is, I strongly believe, software or firmware related — prolly software.
As of Dec 2017, I have a replacement iPad AND Smart Keyboard from a device purchased in late Sept suffering the same problems.
I noticed a distinct correlation — possible causation? — between using the charging port to charge, connect the Apple pencil, or attach any other accessory, such as airpods.
There were, equally, reports of Logitech’s Create Case/Keyboard similarly failing.
I strongly believe that a software loop designed to periodically detect attached accessories (including simply plugging the iPad in to charge it) is failing.
Were I Apple, that’s where I’d look.
Very disappointing performance, Apple.