The origin of the word egregious, from the OED:
mid 16th century (in egregious (sense 2)): from Latin egregius ‘illustrious’, literally ‘standing out from the flock’, from ex- ‘out’ + grex, greg- ‘flock’. Sense 1 (late 16th century) probably arose as an ironical use
Thus, a term that now means outstandingly bad, originated as a word that simply meant outstanding or ilustrious. The ironical context, which resulted in the negative connotation of the word in colloquial speech (although, let’s face it, who uses ‘egregious’ any more, except for English writers – and me, of course) – anyhow, the negative connotation is not clear from this entry. A word that once meant remarkably good is now used to describe something remarkably bad. Evidently, (according to the Virtual Linguist) the word was always used in both contexts – outstanding as well as outrageous – good and bad. Only a truly remarkable word can simultaneously express two opposite ideas at once – although the positive sense of egregious is now considered obsolete.