Jay H. Jasonoff, “The Origin of the Italic Imperfect Subjunctive,” Historische Sprachforschung / Historical Linguistics 104 (1991): 84-105.
If you’re into the history of languages or morphological development, this article is a great resource. It’s quite dense, and is thus a slow read, but it’s well worth the effort to unpack it. Some highlights:
Italic languages originally had two ways of placing the action of a verb in the future. One was based on the Proto-Indo-European (PIE) subjunctive, which was formed with a vowel between the verb’s stem and the personal ending (like the Greek subjunctive λύῃς, which came from λύ + ε + εις) and the other was based on the PIE present desiderative, which was formed with an s between the verb’s stem and personal ending (like the Greek future tense, λύσω). Ultimately, the PIE subjunctive form won out and became the primary way of forming the future tense in Italic languages.
Similarly, Italic languages expressed the pastness of an action in two ways. One came from the PIE perfect tense, which reduplicates the first syllable in a verb (Greek λέλυκα; seen in Latin perfect forms like tetigi). The other came from the PIE aorist, which adds an s between the verb’s stem and personal endings (Greek ἔλυσα; reflected in Latin perfect forms like dixi). Ultimately, the old PIE perfect and aorist were combined into a single verb form, the perfect, which explains why in Latin, the perfect tense carries both a perfective/resultative sense (“I have run three miles”) and an aoristic/undefined sense (“I ran three miles”).
When Italic lost the subjunctive form, which went to form the future tense, the only non-indicative mood it had left was the optative. The optative form, then, was co-opted for duty as the subjunctive. Ultimately, though, because the old optative became the subjunctive mood, Italic needed to fill in the gap left by the optative. Thus, it kept the non-past subjunctive (that is, the present and the perfect subjunctive forms) as true subjunctives (one degree separated from reality; “I would go running if it weren’t raining”), and it made the past subjunctives (the imperfect and the pluperfect subjunctives) into wanna-be optatives (two degrees separated from reality; “I might have gone running if it weren’t raining”).
Or, for those who are more visually-minded, here’s the same information, but as a picture: