There is indeed Foreign accent syndrome . And the simplest explanation is the easiest: people wake up with a kind of speech disorder, which listeners match to whatever accents they are familiar with. It does not mean they are speaking a different languages, or that they have been exposed to another accent natively. Pareidolia, the Wikipedia page politely calls it.
As the Wikipedia article adds,
Despite an unconfirmed news report in 2010 that a Croatian speaker has gained the ability to speak fluent German after emergence from a coma, there has been no verified case where a patient’s foreign language skills have improved after a brain injury.
So “speaking a foreign language” outright doesn’t happen. And if someone was going to wake up from a coma speaking German, Croatia is more plausible than I dunno, Madagascar. Like John Nurse’s answer says, you don’t know a new language out of thin air.