I know that connotation meaning belongs to semantic meaning, but what I'm confused about is the connotation meaning is affected by the context, isn't it? If so, why does it not belong to pragmatic meaning?
The study of meaning is usually divided into two sub-areas, semantics and pragmatics, where semantics is about literal, denotative meaning (looking only at the linguistic form) and pragmatics is about how non-semantic context and semantics interact to generate the broader meaning / communicative function of an utterance. Connotation is considered to be part of pragmatics. Confusion might arise over different meanings or definitions of "semantics", and the fact that sometimes literal semantics is called "sentence / word meaning" and pragmatics is called "speaker meaning".