It came from the same source as "a bolt from the blue" and "out of a clear blue sky", meaning as a great surprise. The idea is that a thunder-bolt is the last thing you expect from a cloudless sky. There may also be a connection with flying, on the basis that an enemy plane attacking yours would be hard to spot against such a backdrop.