No one really knows for sure, because the word has been in the English language for centuries already (the word was “buterfleoge” in Old English).
One story is that they were named so because it was then thought that butterflies, or more precisely, witches that took on the shape of butterflies, stole milk and butter.
Someone else wondered if the word was really meant to be “flutter-by”.
In other languages, the word for these lovely creatures has no such derivation as “butter” + “fly”. One can only guess on why the English language uses such an unlikely name.