Diagnosis
This is almost always caused by the TV's Bravia Sync (CEC) feature misbehaving, where a connected device is sending rogue 'input change' commands.
How to Fix It
Disable Bravia Sync for the problematic HDMI port. Go to Settings > Watching TV > External Inputs > Bravia Sync Settings. Turn 'Bravia Sync control' to OFF. You'll lose single-remote control for that device, but it will stop the random switching.
If That Didn't Work
A faulty HDMI cable can send erroneous CEC signals. Replace the HDMI cable connected to the device you were watching when the switch happened with a new, certified High-Speed HDMI cable.
Heads Up
The TV's own 'Content Bar' or 'Quick Settings' can sometimes be triggered accidentally by remote button presses. Ensure you're not accidentally brushing the 'Input', 'Google Assistant', or 'Quick Settings' buttons on the remote.