History of nice:
Nice is a highly polysemous word. A polysemous word has more than one meaning.
Origin: Ne- (not) + scire (know, same root as 'science') -> nescire (not know) -> nescius (ignorant) -> nice (careless, clumsy, stupid - late 13c). In 14th century, its meaning was foolish, ignorant and stupid ---> semantic change (amelioration) ---> fastidious (late 14c) -> precise, careful (1500's) -> agreeable, delightful (1769) -> kind, thoughtful (1830's) -> pleasant, agreeable and then respectable (19c) -> pleasant and other positive meanings (20c onwards).
Nice and another English word nescience (meaning: ignorant) have the same origin (nescire).
It was borrowed from French, meaning silly and stupid. Years later, nice meant dissolute or extravagant in dress and fashionable. From there, the word went on to mean finely dressed or precise about looks. And then, precise about looks changed to precise about reputation.
As time went on, 'nice' meant something like to have a refined taste. From here, the positive connotations continued with the idea of being cultured, respectable and agreeable.
Finally, after this perplexing history, 'nice' remains a term of approval today. We use it all the time to compliment people.
It entered Modern English through Old French and Middle English from Latin so its meaning has changed over time. This is because of semantic change.
Explanation and citations:
From Merriam Webster:
It is a bit difficult to say with much certainty what the earliest meaning of nice was in Modern English, since by the end of the 14th century there were already a number of different senses of the word — M-W
Some other meanings of 'nice':
'Nice' has meant 'tarty':
Sometimes it went further than this pejorative sense - it had the sense of the modern British slang 'tarty', or '[appropriate to] a woman of promiscuous sexual behaviour'.) — AWE
'Nice' has meant 'fastidious' (around 1500):
Its second main meaning was that of 'precise' or 'fastidious' — AWE
'Nice' has meant 'dissolute':
May we not this day read our sin in our punishment? O what nice and wanton appetites, what curious and itching ears, had thy people in the dayes of plenty? - John Flavel, Husbandry Spiritualized, 1674 — M-W
'Nice' has meant 'chaste':
“But Reddy Wheeler knew Daisy. We were properly introduced. It was quite all right!”
“Yes, but nice girls don’t do this sort of thing, you know--unchaperoned, and so late at night, and all that.” - Fred Jackson, “Young Blood,” Munsey’s Magazine, 1917 — M-W
'Nice' has meant 'finicky':
By the 16th century, the sense of being "very particular" or "finicky" had developed — Word Central
From Merriam Webster:
It's easy to tell which sense is being used in which instance, in part because nice has not been much used to mean “dissolute” or “wanton” in the last several hundred years. But even with modern senses we generally are able to use context to distinguish between shades of meaning. For instance, one of the following uses of nice would be defined as “demanding or marked by great precision,” and one would be defined as “unpleasant - used ironically.”
The difference is not enough to prove confusing, it is true, but it exists, and in nice measurements would have to be allowed for. —Electrical World, 16 Sept. 1911
“I give you my word they did not speak to each other during that dinner, nor would Louise stay to the cotillon. Charlie danced it with Frankie. Nice state of affairs, isn’t it?” I felt myself grow weak. —Lillian Lida Bell, The Love Affairs of an Old Maid, 1893
Why did the meaning of 'nice' change:
The meaning of nice changed because of a common phenomenon called Semantic change.
In semantics and historical linguistics, semantic change refers to any change in the meaning(s) of a word over the course of time. Also called semantic shift, lexical change, and semantic progression. Common types of semantic change include amelioration, pejoration, broadening, semantic narrowing, bleaching, metaphor, and metonymy.
When a word with negative meaning develops a positive meaning, the process is called 'amelioration'.
The literal meaning of ameliorate is to make something unpleasant better.
Example: The best example of amelioration is 'nice'.
'Nice' had negative meanings (ignorant, stupid and silly in 14th century), now it's used in positive sense (pleasant, excellent, admirable etc).
The opposite of amelioration is pejoration
When a word with positive meaning develops a negative meaning, the process is called 'pejoration'.
The literal meaning of pejorate is to make something worse.
A very common example of pejoration is the word 'gay'.
'Gay' originally meant lighthearted and joyous in 13th century. In 14th century, its meaning was bright and showy. It acquired negative connotations (immorality) around 1637. Presently, it's used to mean homosexual. See how it developed negative meaning. It's called pejoration.