[proofplan]
The statement is an equivalence, so we prove both directions. The forward direction is essentially the definition of the subspace topology: restrictions of continuous maps are continuous. The reverse direction is the substance of the lemma: we show that if each restriction pulls closed sets back to closed sets, then $f$ does too. The key arithmetic identity is $f^{-1}(A) = f|_C^{-1}(A) \cup f|_K^{-1}(A)$, which holds because $X = C \cup K$; combined with the fact that closedness in $C$ (or $K$) transfers to closedness in $X$ when $C$ (resp. $K$) is itself closed in $X$, the proof reduces to the finite-union-of-closed-sets property.
[/proofplan]
[step:Prove the forward direction using restriction of continuous maps]
Assume $f: X \to Y$ is continuous. We show $f|_C: C \to Y$ is continuous; the proof for $f|_K$ is identical.
Let $A \subseteq Y$ be closed. Since $f$ is continuous, $f^{-1}(A)$ is closed in $X$. Then
\begin{align*}
(f|_C)^{-1}(A) = \{c \in C : f(c) \in A\} = f^{-1}(A) \cap C.
\end{align*}
Since $C$ carries the subspace topology from $X$, a set is closed in $C$ if and only if it is the intersection with $C$ of a closed set in $X$. Hence $(f|_C)^{-1}(A)$ is closed in $C$. As $A$ was an arbitrary closed subset of $Y$, $f|_C$ is continuous by the closed-set characterisation of continuity.
[/step]
[step:Express $f^{-1}(A)$ as a union of the restriction preimages]
Assume now that $f|_C$ and $f|_K$ are continuous. Let $A \subseteq Y$ be closed. We claim
\begin{align*}
f^{-1}(A) = (f|_C)^{-1}(A) \cup (f|_K)^{-1}(A).
\end{align*}
Indeed, let $x \in f^{-1}(A)$, so $f(x) \in A$. Since $X = C \cup K$, either $x \in C$ or $x \in K$. In the first case $x \in C$ and $f(x) = f|_C(x) \in A$, so $x \in (f|_C)^{-1}(A)$; in the second case $x \in (f|_K)^{-1}(A)$. This proves the inclusion $\subseteq$.
Conversely, if $x \in (f|_C)^{-1}(A)$ then $x \in C \subseteq X$ and $f(x) = f|_C(x) \in A$, so $x \in f^{-1}(A)$; symmetrically for $(f|_K)^{-1}(A)$. This proves $\supseteq$.
[guided]
We want to compute the preimage of $A$ under $f$ in terms of the preimages under the restrictions, since those are the objects we have continuity information about.
Recall the elementary identity for restrictions: if $g: Z \to Y$ is any map and $Z' \subseteq Z$, then $(g|_{Z'})^{-1}(A) = g^{-1}(A) \cap Z'$. Thus
\begin{align*}
(f|_C)^{-1}(A) \cup (f|_K)^{-1}(A) = (f^{-1}(A) \cap C) \cup (f^{-1}(A) \cap K) = f^{-1}(A) \cap (C \cup K) = f^{-1}(A) \cap X = f^{-1}(A),
\end{align*}
where the second equality distributes intersection over union and the third uses the hypothesis $X = C \cup K$. This is the identity we need.
The key point is that this identity decomposes the global preimage into two pieces, each of which we can control via the continuity of the corresponding restriction.
[/guided]
[/step]
[step:Promote closedness in $C$ and $K$ to closedness in $X$]
By continuity of $f|_C$, the set $(f|_C)^{-1}(A)$ is closed in $C$ (with the subspace topology). By definition of the subspace topology, there exists a set $F_C \subseteq X$ closed in $X$ such that $(f|_C)^{-1}(A) = F_C \cap C$. Since $(f|_C)^{-1}(A) \subseteq C$ already, we have $(f|_C)^{-1}(A) = F_C \cap C$ as subsets of $X$.
Now use that $C$ itself is closed in $X$. Then $F_C \cap C$ is the intersection of two closed subsets of $X$, hence closed in $X$. Therefore $(f|_C)^{-1}(A)$ is closed in $X$.
The identical argument, with $K$ in place of $C$, shows that $(f|_K)^{-1}(A)$ is closed in $X$.
[guided]
We have closedness in the subspaces $C$ and $K$, but we need closedness in the ambient space $X$. This upgrade is not automatic for arbitrary subspaces — for instance, $(0, 1)$ is closed in $(0, 2)$ (as a subspace of $\mathbb{R}$) but not closed in $\mathbb{R}$. The upgrade works here precisely because $C$ and $K$ are closed in $X$.
Let us verify this carefully. The subspace topology on $C$ declares $E \subseteq C$ closed iff $E = F \cap C$ for some $F$ closed in $X$. Hence $(f|_C)^{-1}(A) = F \cap C$ for some closed $F \subseteq X$. Since $C$ is closed in $X$, the intersection $F \cap C$ is a finite intersection of closed subsets of $X$, which is closed in $X$ by the axioms of a topological space.
This is exactly where the hypothesis "$C$ is closed in $X$" is consumed. Without it, the result would fail: for instance, the characteristic function $\mathbb{1}_{\mathbb{Q}}: \mathbb{R} \to \{0, 1\}$ is continuous when restricted to $\mathbb{Q}$ and to $\mathbb{R} \setminus \mathbb{Q}$ (each restriction is constant), but is nowhere continuous on $\mathbb{R}$ — and neither $\mathbb{Q}$ nor its complement is closed in $\mathbb{R}$.
[/guided]
[/step]
[step:Conclude that $f^{-1}(A)$ is closed and hence $f$ is continuous]
Combining the previous two steps,
\begin{align*}
f^{-1}(A) = (f|_C)^{-1}(A) \cup (f|_K)^{-1}(A)
\end{align*}
is a union of two sets closed in $X$. A finite union of closed sets is closed, so $f^{-1}(A)$ is closed in $X$.
This holds for every closed $A \subseteq Y$, so $f$ is continuous by the closed-set characterisation of continuity. This completes the reverse direction, and hence the proof of the equivalence.
[/step]