It is highly nontrivial that the connected sum of manifolds is well-defined. First, you actually want to assume that you can thicken your embeddings of discs (the term is "locally flat"); otherwise one of your discs might be one side of the Alexander horned sphere! You want to prove that every embedding of the disc $D^n \hookrightarrow M$ is isotopic (meaning that the two embeddings are homotopic through locally flat embeddings). Two reasonable exercises are to show that if $f$ and $g$ are embeddings, then $g$ is isotopic to an embedding whose image is contained in the interior of the image of $f$; and to prove that if all (locally flat) embeddings of discs are isotopic, then the connected sum is well-defined. You'll then want the "isotopy extension theorem" for locally flat embeddings.
Now what you want to invoke is the annulus theorem to actually construct the final isotopy. This is not easy! You'll note that the Wikipedia article implies that the connected sum of manifolds was only finally proved well-defined in 1982. (It's a bit easier to prove that the connected sum of smooth manifolds is well-defined.)
If you are cynical about such theorems and demand to see proofs before you use these results, the way you should interpret theorems about $M \# N$ is "For every connected sum of $M$ and $N$, ..."
I'm going to assume that you know all about quotient spaces (if you don't then you'll have to learn that because otherwise no answer to your question will make sense).
Another thing you need is the collar neighborhood theorem from differential topology, applied to the boundaries of $X_1$ and $X_2$. That theorem says that there exist neighborhoods $N_1$ of $\partial X_1$ and $N_2$ of $\partial X_2$, and diffeomorphisms $f_i : N_i \to \partial X_i \times [0,1)$ (for each $i=1,2$) such that $f(x) = (x,0)$ for each $x \in \partial X_i$ .
Now choose a diffeomorphism $g : \partial X_1 \to \partial X_2$. And then we have the quotient topological space $Y$ together with the quotient map $q : X_1 \cup X_2 \to Y$ obtained by identifying each $x \in \partial X_1$ with $g(x) \in \partial X_2$, so $q(x)=q(g(x))$.
Let me alter your notation slightly: I'll choose $x_1 = \partial D_1 = \partial X_1$ and $x_2 = g(x_1) \in \partial D_2 = \partial X_2$, which corresponds to the point $x = [x_1] = [x_2] \in Y$ (here I use the notation $[\cdot]$ to denote the corresponding point in the quotient space; I'm unsure whether this is what you intend in your question when you put the $\tilde{}$ symbol over something).
So now I have to describe a manifold chart in $Y$ for the point $x$. To do this, I'll choose a manifold chart in $\partial X_1$ around $x_1$, i.e. an open subset $U_1 \subset \partial X_1$ containing $x_1$ and a diffeomorphism $\phi_1 : U_1 \to B$, where $B$ is the unit open ball in Euclidean space. From this I get a manifold chart in $\partial X_2$ around $x_2$, namely $U_2 = g(U_1)$ and $\phi_2 = \phi_1 \circ g^{-1} : X_2 \to B$.
In $Y$ define the open chart around $x$ as follows:
$$U = q\bigl(f_1^{-1}(U_1 \times [0,1)) \cup f_2^{-1}(U_2 \times [0,1))\bigr)
$$
The map $\psi : U \to B \times (-1,+1)$ will be given by the following formula. Each $y \in U$ has one of two forms, and we give the formula for each form:
- If $y = qf_1^{-1}(z,t)$ for $(z,t) \in B \times [0,1)$ then $\psi(y) = (z,-t) \in B \times (-1,0]$
- If $y = q f_2^{-1}(z,t)$ for $(z,t) \in B \times [0,1)$ then $\psi(y) = (z,t)$
This is well-defined if $y$ has both forms (which only happens when $t=0$).
And then, by tracing through all the definitions and using all the theorems you can possibly find from quotient spaces, it follows that $\psi$ is a homeomorphism from $U$ to $B \times (-1,+1)$.
Best Answer
Wikipedia has an extremely short "Disc Theorem" entry which references Palais' "Extending diffeomorphisms" paper. It says
Disc Theorem. For a smooth, connected, $n$-dimensional manifold $M$, if $f, f'\colon D^n \to M$ are two equi-oriented embeddings then they are ambiently isotopic.
This is one of the fundamental results in Differential Topology, and in particular it implies that connected sums are well-defined wrt choice of embeddings. There might be a simpler proof in $2$D, but this is the standard result which is typically cited for all dimensions.
(Here "ambiently isotopic" means there is an isotopy $H: M\times I \to M$ which begins at the identity map and induces an isotopy between $f$ and $f'$; "equi-oriented" means that $f$ preserves orientation iff $f'$ does. In fact the proof of Palais' theorem shows a bit more: the ambient isotopy can be chosen to be fixed outside of a compact, contractible subspace containing the images of $f$ and $f'$.)
It's been a while since I looked at it, but a proof sketch sort of goes like this: First choose a small open tube around the unit interval $I\subset U\subset \mathbb{R}^2$ and an embedding $\gamma\colon \bar U \to M$ where $\gamma(0) = f(0)$, $\gamma(1) = f'(0)$. Now pick a small disc $D\subset U$ centred at $0$, and construct an ambient isotopy in the tube $F\colon U\times I \to U$ which transports $D$ to a disc centred at $1$. Then you have to construct ambient isotopies $H_1, H_2$ on $M$ which shrink $f(D^n)$ and $f'(D^n)$ down to $\gamma(D)$ and $\gamma(F_1(D))$ respectively (I guess this step uses a linearization trick). Then these three isotopies are pieced together to give the result.