You may have noticed that in every visual work, characters seem to have music playing in their heads at all times. Not songs they've heard. Not even classical tunes theyve listened to. These are tunes that seem to just come out of nowhere, off the top of the character's head.
This technique is used because it makes you sympathize with a character's emotions. Without music, you would not be able to connect with characters and feel their emotions.
If music is shown in one character's perspective, but then the perspective switches to another character who can't hear the music, that's Sudden Soundtrack Stop.
Compare Mickey Mousing, for when music that is meant to set the mood is actually being played by a character in-universe.