OK, if it starts working again by simply by logging out or plugging in a USB device something odd is happening.
Next time the built in keyboard stops responding estimate the last time that you knew the keyboard to be working.
Plug in the USB keyboard and note the time you do this.
Use the USB keyboard to open a terminal by pressing Ctrl, Alt and T together.
Maximise the terminal window, then
Click Edit - Preferences
Under the General tab look for the 'Scrolling' section
Select the 'Unlimited Scrollback' option
Click 'Close' on the Preferences selection.
At the terminal prompt type in the command below followed by return.
In your command, replace the 'since' hh:mm with the estimated time that you knew the inbuilt keyboard was working.and the 'until' hh:mm with the time you plugged in the USB device.
Code:
journalctl -b --since hh:mm --until hh:mm --no-pager
This should display the contents of the log between the since and until times you specify
You can widen the time window if needed but we want to see if anything was logged when the keyboard went off line.
Scroll back to the start of the log and select/copy all the log entries.
Paste into a text file so you can review it and paste it back into the thread.