In Ancient Castillian, words like caja, bajo, and jaraba were originally spelled with an x, and pronounced as "sh".
At some point the spelling was changed from an x to a j, including words like Mejico and Tejas. During that time, the "j" was actually pronounced as a "j" in English. Over time, some words (like Mexico and Texas) reverted back to the 'x' spelling, but retained their 'j' pronunciation. And the letter "j" took on the "h" pronunciation that we know today.