The model does not work with words exactly. It works with tokens - pieces of words, roughly four characters on average in English. Understanding becomes a chain of these pieces rather than one unit. This is a small detail with visible consequences: it is part of why models have historically struggled to count letters in a word or reverse a string, because they are not seeing the letters the way you are.
During training, the model is shown enormous quantities of text with parts hidden, and asked to predict what was hidden. Getting it wrong adjusts its internal parameters very slightly. Repeat that across a large fraction of the written internet and the adjustments accumulate into something that has, in effect, absorbed the statistical shape of how language is used - including how explanations are structured, how code is written, and how arguments are made.
When you send a message, that message plus the conversation so far becomes the context. The model predicts the next token, appends it, and repeats until it decides the response is finished. Nothing is retrieved and nothing is reasoned about in the way a person would - though newer models are trained to produce intermediate working before answering, which improves results on problems that need several steps.
After the main training, models go through further stages that shape their behaviour rather than their knowledge - being taught to follow instructions, to be helpful, and to decline certain requests. This is why two models trained on similar material can feel so different to use. Much of what you experience as a model's personality comes from this stage rather than from the underlying architecture.