Have you looked at
Control Panel > Power Options > Change Plan Settings > Change Advanced Power Settings
Expand
- USB Settings
Then there’s a thing called USB Selective Suspend → Disable?
Maybe you already looked at that. I had some strange usb behavior kind of like that.
Sorry if useless idea!
I don’t know why it would go to sleep when power is plugged in instead of on battery.