The Spanish letter names are explained in chapter 5.4.3 from the Spanish Orthography published in 2010 by the RAE. Following on is a translation into English of the most relevant parts.
The Spanish alphabet derives from the Latin alphabet, and also the letter names. The Greeks had kept or adapted the Phoenician names for the letters, so in Classical Greek the letter names were words that started with sound to be represented. Thus, Phoenician names ʾaleph, bet, gimel became alpha, beta, gamma in the Greek alphabet. On the other hand, the Latin names are phonetic (based on their characteristic sounds).
In Latin, the name for the vowels was their own sound ('a', 'e', 'i'...). This has been kept in Spanish.
The 'i' letter is also named 'i latina' sometimes, when it needs to be differentiated from the 'i griega' (see below).
The consonant names in Latin are also based on their sounds, but adding a vocalic supporting sound. This supporting sound was provided by the letter 'e', which is the one that takes the least effort to be uttered. Some consonant names were created by adding an 'e' after the consonant sound ('be', 'de', 'ge' and so on) and other added the 'e' before ('ef', 'el', 'em' and so on). These names were kept in Spanish, only that we needed to add another 'e' sound for the second group, creating our current 'efe', 'ele', 'eme' and the rest.
C, K, Q
In Latin these letters always represented the /k/ phoneme, so to differentiate them the vocalic sound added was different in each case. The basic case was 'c', named 'ce', and the other were named by adding the vowel that was most frequently used after each: so 'k' was named 'ka' and 'q' was named 'qu'. So the names for C, K, Q were pronounced in Latin as [ké, ká, kú] that gave the current 'ce', 'ka', 'cu'.
As explained in this answer to a question in the Latin language site, the letter 'C' began shifting its pronunciation from /k/ to /ts/ when followed by 'e' or 'i' by the fifth century or probably some time before that, and the change was completed in the seventh century. In the Spanish peninsula the sound move towards /θ/. A similar change suffered the letter 'G' that softened its pronunciation before 'e' and 'i'. That's why we say today /θe/ and not /ke/, and /xe/ and not /ge/, as these changes were completed long before the eleventh century when the Spanish language is considered to start.
X, Y, Z
The 'x' name comes from Latin 'ix', just by reversing the name 'xi' the letter had in Greek, as no Latin word began with that letter or the sound [ks]. Some time after the letter started being named after its sound as the rest of the consonants, so it started to be named 'ex' or 'eks' (using the 'e' as vocalic support) which derived into today's 'equis'. The 'y' was named 'i Graeca' based on its origin (Spanish: 'i griega', though it is also named 'ye' nowadays to follow the main pattern for consonant names), and the 'z' just kept the Greek name 'zeta'.
H, J, V, W
The name 'hache' seems to come from the French name of the letter. The French name hache as well as Italian acca and Catalan hac seem to come from vulgar Latin *hacca, a corrupted imitation of the aspirated sound this letter represented in its origin.
The name 'jota' comes from the Greek name iota, as this letter is a variant for the letter i.
The name 'uve' is quite recent. The letter u/v was named 'v consonante' or 'u consonante' as opposed to 'u vocal'. Since 1869, the 'v' was named just 've', following the most common pattern for consonant names (in fact, in American Spanish it is still its name). Nonetheless, ir order to be able to tell apart 'be' from 've', in 1947 its name changed to 'uve', joining the two values that the letter had: 'u' (vowel) and 've' (consonant).
The name 'uve doble' just reflects the origin of the letter 'w', a duplication of the letter 'v'.
American Spanish variants
Some consonants have other names in the American Spanish. These are:
- b: named 'be larga', 'be grande' and 'be alta'.
- v: named 've', 've corta', 've chica', 've pequeña' and 've baja'.
- w: named 've doble', 'doble ve', 'doble u' and 'doble uve'.