I have to give props to Buffy the Vampire Slayer explaining why it was a musical episode (Scrubs too), but has anyone else ever sat through a musical wondering how the heck everyone breaks out into the same song and dance at once?
I guess you could also do that with a generally non-musical series having a musical episode: they don't really have to explain why it's happening, most people would probably accept "okay guys we're a musical this week for the LOLS."
On an episode of Family Matters with a musical number it's because it's All Just a Dream. Making for one of the few semi-justifiable uses of that trope ever ( the finale of Newhart being an even rarer example of a full justification), because how many ways are there to make sense of a sudden musical number erupting out of nowhere?
What about the musical episode of X-Play, where Morgan and Adam created the 'ultimate hybrid' video game... and it turned out to be a monster (both the game and the episode)? Perhaps a bit of layered symbolism into the idea that Morgan and Adam don't know what makes a good game?