I've seen some really odd behavior with some recent Apple laptops and macOS over the past year or so including the issue you have described in your post. I agree it would seem to be entirely a software issue (it was my first thought too when I first encountered this issue with our organization's laptops), but I really believe it is a bit of both hardware and software just from what I've personally observed.
I've seen some Apple hardware failures have an unexpected side effect within macOS.
Recovery Mode is not a full blown copy of macOS, but a very minimal version which may not be utilizing or accessing the hardware in the exact same way or to the same extent.
The Apple Diagnostics don't mean much unless it shows a failure. A passing diagnostic does not necessarily mean the hardware is good. The service diagnostics which the Apple Store and AASP's have are a bit more involved and may detect a problem that the consumer level diagnostic cannot, but even the service diagnostics may still not find an issue. If Apple or an AASP replaces the Logic Board or Keyboard/Trackpad it will confirm whether the it is a hardware issue or exclusively a software issue.
If you can find a software "fix", then I would definitely be interested in it. It doesn't hurt to try if you have the time and patience to investigate. Unfortunately I couldn't justify the time necessary to look for the needle in the haystack when replacing a part quickly resolved the problem for us.