MacBook Pro 2013 keyboard and trackpad completely freeze
Try plugging in an external USB device, such as a phone or keyboard. I have found recently that this fixed my intermittent keyboard/trackpad issues perfectly.

As for why this is, I read on another site that the internal keyboard and trackpad on Macbooks connect over USB internally, so if the internal USB hub gets reset, it would force the keyboard and trackpad to reconnect. And after thinking about it, I am pretty certain that any time I have had keyboard/trackpad freezes like yours, I was also plugging in my Android phone, either to charge it or run diagnostics. I am pretty sure that plugging in my phone has been causing these issues.