This is most likely happening to you when you leave the computer for a while, then come back. Why?
- You have a monitor connected via HDMI.
- HDMI supports carrying audio, and is thus an audio output device.
- When the monitor powers off due to inactivity , then back on, this audio device becomes available again.
- PulseAudio is configured to switch its default output device to any device becoming available.
How to stop this from happening? Edit the file /etc/pulse/default.pa
and comment-out the line:
load-module module-switch-on-port-available
by prepending a hash mark (#) to it.
Credit: This AskUbuntu answer.