As guifa says in a comment, the sound change of /ks/ to /x/ was blocked when the letter x was followed by a consonant. In these circumstances /ks/ was generally reduced to /s/, with the /ks/ pronunciation re-emerging as a form of hypercorrection:
The evidence indicates that this Latin letter represented [ks]. The development of the sound in Vulgar Latin and in the Romance languages varied from region to region, with more changes occurring in Spanish than in any other case.
In Castilian territory the [ks] > [js] > [sj] > [š]. This last phone leveled with [ž] from Latin J and G (e, i) in the fifteenth and sixteenth centuries, and the resulting [š] gradually became [χ] by 1650. In the nineteenth century the Spanish Royal Academy did away with the spelling x, except in Latinisms such as examen, sexta, and words such as dixe are now spelled with j (dije). In Mexico, especially, the x has been retained in words of Indian origin to represent a primitive [š] (Mexico, Xalapa, Oaxaca), now [χ], and in Yucatan one still hears the [š] (Uxmal) among the Maya- speaking inhabitants or among foreigners ...
It is to be noted that the evolution of X to an ultimate [χ] did not take place when it was supported by a consonant as in FRÁX(I)NU > fresno, SÉXTA > siesta, and where X has been retained before a consonant, generally represents [s] (extraño [estráño], experiencia [esperjénsja]).135
In the other Romance languages the -X- [ks] usually became a sibilant or retained its original Latin value. In Catalan and Portuguese the descendents are [s] (x) and [s] (ss) and the letter X has been extended to represent [š] of other origins than Latin X:
Arabic [š] (P. xadrez C. aixedres), Latin -PS- (P. C. caixa). In Catalan the [č] is represented normally by tx.136
135. In the latter type [s] (= x preceding consonant), hypercorrection often produces [ks] or [gs] through pedantic school teaching, i.e. sexta [séksta] and extrano [ekstráno]. This is not the popular pronunciation however.
Thus, words with an 'x' spelling come under three categories in Spanish:
- ...xV... (x followed by vowel, naturally inherited from Latin to Spanish)
⟨x⟩ /ks/ → ⟨x⟩ [js] → ⟨x⟩ [sj] → ⟨x⟩ /ʃ/ → ⟨j⟩ /ʃ/ → ⟨j⟩ /x/
e.g. exemplus → exemplo → ejemplo
- ...x... (loanword at time when "x" was pronounced
⟨x⟩ /ʃ/ → ⟨j/x⟩ /ʃ/ → ⟨j/x⟩ /x/
e.g. (Nahuatl: Mēxihco → ) México → Méjico → México
e.g. (Catalán: boxus → boix → ) box → boj
...xC... (x followed by consonant, naturally inherited from Latin to Spanish)
⟨x⟩ /ks/ → ⟨x⟩ [s] → ⟨x⟩ [ks]~[gs]~[s]
e.g. expertus → experto
...x... (x, learned Latin borrowing)
⟨x⟩ /ks/ → ⟨x⟩ [ks]~[gs]~[s]
e.g. proximus → próximo