The word bolt has many uses, but all suggest surprising quickness and all originated as a reference to an arrow from a crossbow.
The word “thunderbolt” for lightning first appeared in the sixteenth century.
While the word “blue” as a description of a clear sky appeared about a hundred years later.
Since nothing could be more surprising than lightning from a cloudless sky, a “bolt from the blue” entered the language as a description of a sudden and unexpected event.