Even as a native speaker I don't know the reason for this: why is the "x" in México, Texas or Xavier pronounced as the letter "j"?
In Old Spanish, words like "caja", "bajo", and "jarabe" were originally spelled with an "x", and pronounced as "sh" (voiceless palato-alveolar sibilant).
In 1815 the spellings were officially changed from an "x" to a "j" by the RAE, including words like "Méjico" and "Tejas". By this time, the "j" was pronounced the same as "x" (previously it was pronounced like a French "j" (voiced palato-alveolar sibilant)).
Over time, some words (like "Méjico", "Tejas", "Oajaca", and "Javier") reverted back to the "x" spelling, but retained their "j" pronunciation. And the letter "j" took on the "h" pronunciation that we know today.
Here is an excellent article on the subject.
X pronunciation in Spanish:
The Spanish x is usually pronounced as the English ks between vowels, or as the English s before consonants and at the beginning of words. In words of foreign/indigenous origin, it is pronounced as the English h or sh.
In the two examples you provided, the origin of the words is a foreign or indigenous language:
The name México is Aztec in origin, so also foreign/indigenous.
The native Spanish version of the name Xavier is Javier, and therefore pronounced with a J sound. Compare, for instance, the Wikipedia pages on Francis Xavier in English and Francis Javier in Spanish. If the name is ever spelled as Xavier in Spanish, it seems it is likely to be pronounced as with an English s sound.