Linux has multiple virtual consoles. Ctrl+Alt+Fn switches between these consoles. When you switch from console 7 to console 2, the input and output peripherals are re-routed from console 7 to console 2. When console 7 is inactive, it has no access to the input/output peripherals: the display isn't shown on the screen, the applications don't receive keyboard input, etc.
For historical reasons, sound input and output uses completely different channels from input devices such as keyboard and mouse and from video displays. Console devices (the abstraction in the operating system) cover keyboard and video but not sound. The most common basic implementation of sound on a Unix system is independent from that system, and permission to use the sound peripherals is granted based on group membership rather than on ownership of the console. This is in fact a design deficiency.
Ubuntu has set things up so that the session logged into the console, and only them, has access to the audio device. If you switch consoles, you lose access to the audio device, unless you also log into that other console. This is what really should have been done from the start, but wasn't because the designers of console interfaces weren't thinking about sound.
When you switch to another console, your programs keep running, because the CPU is not associated with a console but with a machine: anyone with an account on the machine is allowed to use CPU time. The same goes for other resources such as memory and files (subject to permissions). It's only interactions with the user that are governed by console ownership. Your sound stops playing when you switch to a console where you aren't logged in because your programs lose the privilege to access the sound output device.
I believe that Ubuntu implements access control via Polkit, but I don't know exactly how this works.