The vowels represented in most European lanaguages (but not English) by /a/, /o/, and /u/ are back vowels: in pronouncing them the tongue is positioned back toward the throat. The vowels represented by /e/ and /i/ are front vowels: the tongue is positioned toward the front of the mouth.
The /k/ sound represented by Latin /c/ is articulated with the tongue at the back of the mouth. When the syllable /ka/ or /ko/ or /ku/ is uttered, the tongue doesn't have to move very far, if it all. But with the syllable /ke/ or /ki/, the tongue must shift rapidly toward the front of the mouth. The same is true with the voiced consonant /g/.
Consequently, there is a physiological tendency to alter the pronunciation of /k/,/g/ before /e/,/i/—to position the tongue further forward for the consonants in anticipation of the following vowel.
At some point during the Late Roman Empire this colloquial palatalization (reinforced by similar movements of other consonants) became the “accepted” pronunciation. /k/,/g/ before /e/,/i/ became /tʃ/,/dʒ/, evident in modern Ecclesiastical Latin. The pronunciation changed, but not the spelling: for to change the spelling would cut writers and readers off from their literary heritage.
These pronunciations were inherited (and developed further) by Latin's heirs, the Romance languages. And in due course they passed to English. When English literature revived a century or so after the Conquest, its writers were employing a language greatly enriched by French lexicon and were addressing an audience for whom the “literary” languages were French and Latin. These writers naturally adopted French orthography, and its distinct front and back pronunciations for /c/ and /g/.