[proofplan]
Both parts verify continuity by showing that the preimage of every open (equivalently, closed) set has the required property. For the open pasting, the preimage of any open $V \subset Y$ is the union $\bigcup_\alpha (f|_{U_\alpha})^{-1}(V)$; each piece is open in $U_\alpha$, hence open in $X$ by the [Transitivity of Openness and Closedness in Subspaces](/theorems/1041), so the union is open in $X$. For the closed pasting, we use the closed-preimage characterisation of continuity and the fact that a finite union of closed sets is closed.
[/proofplan]
[step:Prove open pasting: continuity from an open cover]
Let $V$ be open in $Y$. We show $f^{-1}(V)$ is open in $X$. Since $\{U_\alpha\}_{\alpha \in I}$ covers $X$,
\begin{align*}
f^{-1}(V) = \{ x \in X : f(x) \in V \} = \bigcup_{\alpha \in I} \{ x \in U_\alpha : f(x) \in V \} = \bigcup_{\alpha \in I} (f|_{U_\alpha})^{-1}(V).
\end{align*}
For each $\alpha \in I$, the restriction $f|_{U_\alpha}: U_\alpha \to Y$ is continuous by hypothesis, so $(f|_{U_\alpha})^{-1}(V)$ is open in $U_\alpha$. Since $U_\alpha$ is open in $X$, by the [Transitivity of Openness and Closedness in Subspaces](/theorems/1041) (part 1), $(f|_{U_\alpha})^{-1}(V)$ is open in $X$. An arbitrary union of open sets in $X$ is open, so $f^{-1}(V)$ is open in $X$.
[guided]
We verify continuity of $f$ via the open-preimage criterion. Let $V$ be any open set in $Y$. We must show $f^{-1}(V)$ is open in $X$.
Since $\{U_\alpha\}_{\alpha \in I}$ is an open cover of $X$, every $x \in X$ belongs to at least one $U_\alpha$. Therefore
\begin{align*}
f^{-1}(V) = \bigcup_{\alpha \in I} (f|_{U_\alpha})^{-1}(V).
\end{align*}
To verify this equality: $x \in f^{-1}(V)$ means $f(x) \in V$, and since $x \in U_\alpha$ for some $\alpha$, we have $x \in (f|_{U_\alpha})^{-1}(V)$. Conversely, if $x \in (f|_{U_\alpha})^{-1}(V)$ for some $\alpha$, then $f(x) = f|_{U_\alpha}(x) \in V$, so $x \in f^{-1}(V)$.
Now each set $(f|_{U_\alpha})^{-1}(V)$ is open in $U_\alpha$ (by continuity of $f|_{U_\alpha}$). By the subspace topology, this means $(f|_{U_\alpha})^{-1}(V) = W_\alpha \cap U_\alpha$ for some $W_\alpha$ open in $X$. Since $U_\alpha$ is itself open in $X$, the intersection $W_\alpha \cap U_\alpha$ is open in $X$ — this is precisely part 1 of the [Transitivity of Openness and Closedness in Subspaces](/theorems/1041). Finally, $f^{-1}(V) = \bigcup_\alpha (W_\alpha \cap U_\alpha)$ is a union of open sets in $X$, hence open in $X$.
The openness of each $U_\alpha$ is essential here. If $\{U_\alpha\}$ were merely a cover by arbitrary subsets, the sets $(f|_{U_\alpha})^{-1}(V)$, while open in $U_\alpha$, would not necessarily be open in $X$, and the argument would break down.
[/guided]
[/step]
[step:Prove closed pasting: continuity from a finite closed cover]
Let $F$ be closed in $Y$. We show $f^{-1}(F)$ is closed in $X$ using the [closed-preimage characterisation of continuity](/theorems/1010). We have
\begin{align*}
f^{-1}(F) = \{ x \in X : f(x) \in F \} = \{ x \in C_1 : f(x) \in F \} \cup \{ x \in C_2 : f(x) \in F \} = (f|_{C_1})^{-1}(F) \cup (f|_{C_2})^{-1}(F).
\end{align*}
For $j \in \{1, 2\}$, the restriction $f|_{C_j}: C_j \to Y$ is continuous by hypothesis. Since $F$ is closed in $Y$, $(f|_{C_j})^{-1}(F)$ is closed in $C_j$. Since $C_j$ is closed in $X$, by the [Transitivity of Openness and Closedness in Subspaces](/theorems/1041) (part 2), $(f|_{C_j})^{-1}(F)$ is closed in $X$. The union of two closed sets is closed, so $f^{-1}(F)$ is closed in $X$. By the closed-preimage characterisation, $f$ is continuous.
[guided]
For the closed pasting, we switch to the equivalent characterisation of continuity: $f$ is continuous if and only if the preimage of every closed set is closed (see [Closure Characterisation of Continuity](/theorems/1010)).
Let $F$ be closed in $Y$. Since $X = C_1 \cup C_2$,
\begin{align*}
f^{-1}(F) = (f|_{C_1})^{-1}(F) \cup (f|_{C_2})^{-1}(F).
\end{align*}
Each $f|_{C_j}$ is continuous by hypothesis, and $F$ is closed in $Y$, so $(f|_{C_j})^{-1}(F)$ is closed in $C_j$ (by the closed-preimage characterisation applied to $f|_{C_j}$). Since $C_j$ is closed in $X$, the [Transitivity of Openness and Closedness in Subspaces](/theorems/1041) (part 2) gives that $(f|_{C_j})^{-1}(F)$ is closed in $X$. Finally, $f^{-1}(F) = (f|_{C_1})^{-1}(F) \cup (f|_{C_2})^{-1}(F)$ is a finite union of closed sets in $X$, hence closed in $X$.
Why do we need the cover to be finite and closed, rather than arbitrary? The argument relies on a finite union of closed sets being closed. An infinite union of closed sets need not be closed: $\bigcup_{n=1}^\infty \{1/n\} = \{1, 1/2, 1/3, \ldots\}$ is not closed in $\mathbb{R}$ (the limit point $0$ is missing). Correspondingly, the closed pasting lemma fails for infinite closed covers.
Why not use open preimages, as in part 1? If $C_j$ is closed but not open, the transitivity theorem does not guarantee that sets open in $C_j$ are open in $X$. Switching to the closed-preimage formulation lets us exploit the closedness of $C_j$.
[/guided]
[/step]