late 14c., "morally upright, righteous in the eyes of God" ("Now chiefly as a Biblical archaism" - OED); also "equitable, fair, impartial in one's dealings;" also "fitting, proper, conforming to standards or rules;" also "justifiable, reasonable;" from Old French juste "just, righteous; sincere" (12c.) and directly from Latin iustus "upright, righteous, equitable; in accordance with law, lawful; true, proper; perfect, complete" (source also of Spanish and Portuguese justo, Italian giusto), from ius "a right," especially "legal right, law" (see jurist; from Latin ius also come English jury (n.), injury, etc.).
From c. 1400 as "right-minded, good in intention;" from early 15c. as "legal, lawful, right in law." Also "exact, precise; marked or characterized by precision; having correct dimensions" (late 14c.); of narrations, calculations, etc., "accurate, correct" (early 15c.). The sense in music, "harmonically pure, correct, and exact" is by 1850.
The more mundane Latin law-word lex covered specific laws as opposed to the body of laws. The noun meaning "righteous person or persons; Christ" is from late 14c. (The neuter adjective in Latin was used as a noun, iustum, "what is right or just").
c. 1400, "precisely, exactly;" late 15c., "fittingly, snugly;" c. 1500, "immediately;" from just (adj.) and paralleling the adverbial use of French juste (also compare Dutch juist, German just, from the adjectives).
The original sense of "exactly" in space, time, kind, or degree; "precisely, without interval, deviation, or variation" is preserved in just so"exactly that, in that very way" (1751), just as I thought, etc. But the sense decayed, as it often does in general words for exactness (compare anon, soon), from "exactly, precisely, punctually" to "within a little; with very little but a sufficient difference; nearly; almost exactly;" then by 1660s to "merely, barely, by or within a narrow margin (as in just missed). Hence just now as "a short time ago" (1680s). Also "very lately, within a brief period of time" (18c.). It is also used intensively, "quite" (by 1855).
Just-so story is attested 1902 in Kipling, from just so "exactly that, in that very way."