Dominik Lukes' answer is quite right.
I wanted to elaborate on the specific development: all of the sounds associated with the letter "j" in present-day languages are ultimately based on the front high semivowel sound that "j" is currently used for in German. (This is probably in part why the letter "j" is used in IPA for the semivowel sound).
The letter "j" originated as a graphical variant of the letter "i", which typically is used to represent the front high vowel [i], which is pretty much a syllabic equivalent to [j].
The other pronunciations of "j" developed as follows:
In Romance languages, Latin /j/ (originally written with the letter I
) developed via regular sound change to something like [ɟ] or [dʒ] in certain contexts. (Not necessarily in all phonetic environments! And there were other sources of the sound [dʒ]. But the specifics depend on the particular language we're talking about.)
French had the sound [d͡ʒ] when the word "just" was borrowed from it into English, and English speakers have mostly retained this pronunciation. French speakers later simplified the affricate to a fricative [ʒ].
The story of how Spanish got "j" = /x/ is the longest. In Spanish, the letter "j" at one point was used to represent the sound /ʒ/, as in modern French, probably for similar reasons. The sound /ʒ/ occurred in inherited native Spanish vocabulary as the reflex of word-initial Latin /j/ before back vowels (as in your example justo < L. iustus, or juego < iocum). It also occurred word-medially as the reflex of Latin "l" in certain palatalizing contexts, in words like ajo < alium, fijo < filius, ojo < oculus.
Eventually, Spanish [ʒ] was devoiced and merged with the reflex of [ʃ] (which used to be spelled with "x"), and the merged reflex was further retracted to [x]. Because of the merger, in modern Spanish spelling the letter "j" is used in many words that used to be spelled with "x": e.g. ejemplo.
(Interestingly, in some regional varieties of Spanish the sound /ʝ/ (often written "y") has gone through or is going through similar changes to the ones that Latin /j/ went through centuries before in words like justo. Spanish speakers in certain areas may realize the sound as a voiced affricate like [dʒ], a voiced fricative like [ʒ], or a devoiced fricative like [ʃ].)
Sound changes and examples taken from "History of Spanish Consonants" from The Linguistics of Spanish, Mackenzie, Ian. 1999–2017.
So to summarize: the various pronunciations of "j" can all be explained as resulting from sound changes in various languages that affected original /j/: however, this does not mean that every particular word in a modern language spelled with "j" used to be pronounced with the sound [j].