I think the best way to understand the pasting lemma is to understand why a "naive" version of it is false:
(Incorrect "theorem") Suppose $A,B$ are subspaces of a topological space $X$, and $f:A\rightarrow Y$, $g:B\rightarrow Y$ are continuous functions which agree on the intersection of their domains (that is, for $x\in A\cap B$ we have $f(x)=g(x)$). Then the "union" of $f$ and $g$ $$A\cup B\rightarrow Y: x\mapsto\begin{cases}
f(x) & \mbox{ if } x\in A\\
g(x), & \mbox{ if } x\in B\\
\end{cases}$$ (which makes sense since $f$ and $g$ agree on $A\cap B$) is again continuous.
To see why this is false, consider for example $A=[0,1]$, $B=(1,2]$, $f:[0,1]\rightarrow\mathbb{R}: x\mapsto 0$, and $g: B\rightarrow\mathbb{R}: x\mapsto 1$ (where all spaces involved have the usual topologies). The union of $f$ and $g$ is the function $$[0,2]\rightarrow\mathbb{R}: x\mapsto\begin{cases}
0 & \mbox{ if } x\le 1\\
1 & \mbox{ if } x>1\\
\end{cases}$$ which is not continuous.
So we have a naive idea that gluing together continuous functions should result in a continuous function, but a simple counterexample to the most obvious way of stating that. The correct pasting lemma is what we get when we realize what additional hypotheses we were missing in order to rule out counterexamples like the above - namely, that both $A$ and $B$ must be closed (this can actually be weakened somewhat, but that's not worth focusing on at first).