I've been wondering about that for quite a long time already. My MacBook Pro (Retina, 15-inch, Mid 2015) runs on Mojave (10.14.4) and whenever i'm plugging off my headphones from the MacBook to switch to the internal Speakers the pitch of the outcoming audio is about 3 semitones up and after about 15 seconds it switches back to the original audio signal.
Honestly i don't remember for how long this problem is occurs but i think i noticed it first after a major software version update. As i'm developing myself i'm just curious how something like this can happen, it makes no sense to me at all. (I can only guess it's a software driver bug)
A good friend of mine was also running a Mid 2015 Macbook Pro 15" and he never had that problem.