MBP 2013 keyboard & trackpad freeze after USB disconnect while sleeping
Workaround

When you find yourself in this situation, you should be able to just briefly press the power button. Just a quick half-second press. In doing so you'll be prompted to restart, shutdown, etc.

Potential fix

It may be worth you resetting the System Management Controller (SMC) to see whether this resolves the issue in the longer term.

To do this on your model of MBP, follow these steps:


Shut down your MBP
Keep the MagSafe adapter (power cable) plugged in.
Press at the same time shiftoptioncontrol (on the left side of the built-in keyboard) and the power button
Let go
Turn your computer back on with the power button.


Some tests

Have you tested to see whether this behaviour is replicated on all USB ports?

Another test would be to boot into Safe Mode and see if it is replicated, either during Safe Mode or again afterwards. I understand it's an intermittent issue, so these sorts of tests will require determination/patience.

To boot into Safe Mode:


Fully shut down your Mac
Restart your Mac
Immediately press the Shift key and keep it down 
Let go of the Shift key when you see the login window (NOTE: If you have FileVault enabled you may need to log in twice).
Try testing for the same behaviour
Exit Safe Mode by restarting your Mac as normal