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:
#-X-
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 [s] (Mexico, Xalapa, Oaxaca), now [χ], and in Yucatan one still hears the [s] (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:
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 [*extráno]. This is not the popular pronunciation however.
Arabic [š] (P. xadrez C. aixedres), Latin -PS- (P. C. caixa). In Catalan the [č] is represented normally by tx.136
The -X- in Italy generally became [s] (ss), as it did in France, and the popular French orthographic x (paix, and the plurals chateaux, cheveux) simply represent a former final -s or -z written with a peculiar flourish so as to resemble somewhat an x.137
The prefix EX- in Italian and Romanian, by apheresis or loss of e- (along with prosthetic e-) was generally reduced to [s] or [z], depending on whether it was followed by a mute or voiced consonant:
- EXPÓNĚRE > Rm. spune [spúne], but It. esporre [espór̃e]
- ESCUTULĀRE > It. scotolare [sk-], Rm. scutara [sk-]
- EXVENTĀRE > It. sventare [zventáre], Rm. zvinta [zv-]; cf. Sard. izventare, C. Pr. esventar [-ez-], and Fr. éventer < OFr. esventer138
Before the front vowels e and i, however, Italian generally palatalized the [ks], spelled sce, sci [še, ši].
Examples of standard treatments of -X-, showing the variety of treatments, are:
- EXEMPLU > It. scempio [5-], esempio [ez-], Sp. ejemplo [ex-], P- exemplo [ez-], C. exemple [egs-], Fr. exemple [egz-]
- EXPECTARE > It. aspettare [as-], Sard. istettare ...
<! >
An Introduction to Romance Linguistics, Delos Lincoln Canfield, John Cary Davis (p.92-93)