@kitten If I recall correctly, they're actually unrelated.
The "speech bubble" started out as just a regular text box containing the dialogue similar to a caption in newspaper cartoons, but since it was hard to tell who was speaking at times, they separated each speaker into their own box and used lines to connect who was talking with their dialogue box. This eventually became the little arrow thing on the speech bubble.
And the "thought bubble" used to be just clouds; in some early cartoons, the cartoonist felt like putting sarcastic satirical supplementary text into a big text box like dialogue was a bit cheesy and obvious, so they would instead hide the commentary in a cloud floating by, similar to how you'd see clouds with a shape resembling something. It eventually turned into "thoughts" of a character, and again to indicate who was the one thinking, they used a trail of smaller clouds.
Then they got closer together as people started merging the two concepts