Topology/Universal property of topological sum in slightly sharper form

A slightly sharper result than the universal property of topological sum is introduced, which is just an excercise given in.

Introduction
A topological sum of two topological spaces $$X_1$$, $$X_2$$ is a triple of a topological space $$X$$ and two continuous functions $$i_1\colon X_1\to X$$, $$i_2\colon X_2\to X$$ that satisfies the following universal property. \begin{matrix} X                         & \xleftarrow{i_2}         & X_2                          \\ {\scriptstyle i_1}\uparrow & \searrow{\scriptstyle f} & \downarrow{\scriptstyle f_2} \\ X_1                       & \xrightarrow[f_1]{}      & Y \end{matrix} $$ A topological sum of two spaces always exists, and is unique up to homeomorphism. So we can denote it by $$X_1\sqcup X_2$$. Since the inclusion functions $$i_1$$, $$i_2$$ are both embeddings we can denote $$i_1(X_1)$$, $$i_2(X_2)$$ simply by $$X_1$$, $$X_2$$. With this notation the topological sum $$X_1\sqcup X_2$$ is as a set the disjoint union of $$X_1$$ and $$X_2$$, and a subset $$U\subset X_1\sqcup X_2$$ is open if and only if $$U\cap X_1$$ is open in $$X_1$$ and $$U\cap X_2$$ is open in $$X_2$$.
 * For every topological space $$Y$$ and continuous functions $$f_1\colon X_1\to Y$$, $$f_2\colon X_2\to Y$$, there is a unique continuous function $$f\colon X\to Y$$ such that $$fi_1=f_1$$ and $$fi_2=f_2$$, i.e. the following diagram commutes.

The following theorem characterizes when a topological space can be seen as a topological sum of two given subspaces.

Theorem 1. Let $$X$$ be a topological space and $$X_1,X_2\subset X$$ two subsets. Let $$i_1\colon X_1\to X_1\sqcup X_2$$, $$i_2\colon X_2\to X_1\sqcup X_2$$, $$j_1\colon X_1\to X$$, $$j_2\colon X_2\to X$$ be inclusion functions. Then the following two conditions are equivalent.
 * (a) $$X=X_1\sqcup X_2$$. That is, the unique function $$f\colon X_1\sqcup X_2\to X$$ defined by $$fi_1=j_1$$, $$fi_2=j_2$$ is a homeomorphism.
 * (b) $$X=X_1\cup X_2$$, $$X_1\cap X_2=\varnothing$$, and both $$X_1$$, $$X_2$$ are open in $$X$$

Proof. (a) ⇒ (b). $$X_1$$ is open in $$X_1\sqcup X_2$$, since $$X_1$$ is open in $$X_1$$ and $$\varnothing$$ is open in $$X_2$$. $$X_2$$ is open for a similar reason. (b) ⇒ (a). Suppose $$U_1$$ is open in $$X_1$$ and $$U_2$$ is open in $$X_2$$. Then, because $$X_1$$, $$X_2$$ are both open in $$X$$, $$U_1$$, $$U_2$$ is open in $$X$$ and so $$U_1\cup U_2$$ is open in $$X$$.

Main result
According to the universal property of topological sum, a function $$f\colon X_1\sqcup X_2\to Y$$ from the topological sum of topological spaces $$X_1$$, $$X_2$$ to another topological space $$Y$$ is continuous, if both $$f\restriction X_1\colon X_1\to Y$$ and $$f\restriction X_2\colon X_2\to Y$$ are continuous. This is a special case of the following theorem.

Theorem 2. Let $$X$$ be a topological space and $$X_1,X_2\subset X$$ two subsets. Suppose that $$X=X_1\cup X_2$$, and that $$X\setminus(X_1\cap X_2)=X_1\setminus X_2\sqcup X_2\setminus X_1$$. Let $$Y$$ be a topological space. Then a function $$f\colon X\to Y$$ is continuous if both $$f\restriction X_1$$ and $$f\restriction X_2$$ are continuous.

Proof of the main result
Lemma 1. Let $$X$$, $$Y$$ be topological spaces, $$x\in X$$ and $$f\colon X\to Y$$. Let $$A\in\mathcal N(x)$$ be a neighbourhood of $$x$$ in $$X$$. If $$f\restriction A$$ is continuous at $$x$$, then $$f$$ is continuous at $$x$$.

Proof. Let $$U\in\mathcal N(f(x))$$ be any neighbourhood of $$f(x)$$ in $$Y$$. Then $$f^{-1}(U)\cap A$$ is a neighbourhood of $$x$$ in $$A$$. So there is an $$N\in\mathcal N(x)$$ such that $$f^{-1}(U)\cap A=N\cap A$$. This and $$A\in\mathcal N(x)$$ imply that $$f^{-1}(U)\cap A\in\mathcal N(x)$$, and so $$f^{-1}(U)\in\mathcal N(x)$$.

Proof of Theorem 2. We show that $$f$$ is continuous at every point $$x\in X$$. If $$x\in\operatorname{int}X_1$$ or $$x\in\operatorname{int}X_2$$, then by Lemma 1 $$f$$ is continuous at $$x$$. If $$x\not\in\operatorname{int}X_1$$ and $$x\not\in\operatorname{int}X_2$$, then it is easily verified that $$x\in X_1\cap X_2$$. Suppose otherwise that $$x\in X_1\setminus X_2$$. Then $$X_1\setminus X_2$$ is open in $$X\setminus(X_1\cap X_2)$$ and so there is a $$V\subset X$$ such that $$X_1\setminus X_2=V\setminus(X_1\cap X_2)$$. Then $$x\in V\subset X_1$$ and this is impossible since $$x\not\in\operatorname{int}X_1$$.

Now let $$U\in\mathcal N(f(x))$$ be any neighbourhood of $$f(x)$$. Then there are $$M,N\in\mathcal N(x)$$ such that $$f(M\cap X_1)\subset U$$ and $$f(N\cap X_2)\subset U$$. Then we have $$M\cap N\in\mathcal N(x)$$ and $$f(M\cap N)\subset U$$, from which $$f$$ is continuous at $$x$$.