The proof of the Pasting Lemma at Wikipedia is correct, but a bit unclear. In particular, it does not clearly show how the hypothesis that X, Y are both closed is being used. It actually has something to do with subspace topology.
I have added some clarifications here:
Pasting Lemma (Statement)
Let , be both closed (or both open) subsets of a topological space such that , and let also be a topological space. If both and are continuous, then is continuous.
Let be a closed subset of . Then is closed in since it is the preimage of under the function , which is continuous. Hence for some set closed in . Since is closed in , is closed in .
Similarly, is closed (in ). Then, their union is also closed (in ), being a finite union of closed sets.