When I copy the text from the source to the emacs buffer ...
What you copy depends upon the application you are copying from. Some applications release UTF-8 encoded strings while others use different formats. Emacs uses the variable
selection-coding-system to determine whether to decide the encoding from the data or presume a particular encoding. See the documentation of
selection-coding-system for more details. Emacs has its own internal representation
utf-8-emacs, so any text insertion has an implicit conversion into this representation.
When emacs write the buffer to a text file...
For an unconfigured emacs, I believe emacs uses
select-safe-coding-system to determine a coding system or prompt the user if undecided. Here is an excerpt from the documentation of
select-safe-coding-system that determines when emacs prompts for a coding system choice.
Source (Formatting mine)
default-coding-system is non-nil, that is the first coding system to try; if that can handle the text,
select-safe-coding-system returns that coding system. It can also be a list of coding systems; then the function tries each of them one by one. After trying all of them, it next tries the current buffer's value of
buffer-file-coding-system (if it is not undecided), then the default value of
buffer-file-coding-system and finally the user's most preferred coding system, which the user can set using the command
prefer-coding-system (see Recognizing Coding Systems).
If one of those coding systems can safely encode all the specified text,
select-safe-coding-system chooses it and returns it. Otherwise, it asks the user to choose from a list of coding systems which can encode all the text, and returns the user's choice."