The resulting object will be (assuming everything's compact, say...) an orientable manifold, but not an oriented one. If you want it to be oriented, with the orientation matching that of $M_1$, say, then the map $f$ should be orientation reversing (which may not be possible without reversing the orientation on $M_2$, and hence the induced orientation on $\partial M_2$).
If you think hard about two unit disks in the plane, joined to make a sphere, you'll see what I mean.
post-comment edits
A manifold $M$ is a topological space $X$ together with a (maximal) atlas $A$ that satisfies certain rules that are well-known to the questioner, so I won't write them out. An oriented manifold is the same thing, together with a subset $S$ of the atlas that consists of charts that are declared to be "orientation preserving" (and which, when they have overlapping domains, satisfy something that's the equivalent (in the smooth case) of the transition function's derivative having positive determinant on the overlap).
To any oriented manifold, $(X, A, S)$ there's an associated manifold $(X, A)$ gotten by ignoring the orientation.
If we glue oriented manifolds $M_1$ and $M_2$ together as in the question and if their boundaries are each connected and $f$ is an orientation-reversing homeomorphism between them, then $M = M_1 \cup_f M_2$ is orientable, and indeed, the orientation can be made consistent with that of $M_1$ and $M_2$, in the sense that both $M_1$ and $M_2$ are embedded in $M$, and the embeddings are orientation-preserving. The glued up manifold is orientable, but until we pick an orientation, it's just a manifold! And the homeomorphism class of that manifold is independent of the orientations of $M_1$ and $M_2$. That's the claim that Michael Albanese, in the comments, seems willing to believe. Let's look at the orientation preserving case now.
If $f$ happens to be orientation-preserving, then we can reverse the orientation on $M_2$ to get a different oriented manifold, $M_2'$, and a map $f' : \partial M_1 \to \partial M_2': x \mapsto f(x)$ which is exactly the same as $f$, except that the target oriented-manifold is now $M_2$ with the other orientation. Note, too, that $M_2'$ and $M_2$ are homeomorphic as manifolds, by the identity map, but are not necessarily homeomorphic by an orientation-preserving homeomorphism.
If we now build $M' = M_1 \cup_{f'} M_2'$, it's homeomorphic to $M$, but not necessarily oriented-homeomorphic. It's orientable, and with the right orientation, we find that $M_1$ and $M_2'$ are both embedded in it by orientation-preserving embeddings.
On the other hand, it's not true that $M_2$ is embedded in it by an orientation-preserving embedding.
What IS true is that $M_2$ is embedded in it as a topological submanifold-with-boundary.
In the case Michael asked about, where $\partial M_1 = \partial M_2 = S^3$, and $M_1$ and $M_2$ are both $\Bbb CP^2$, we get that
$$
M' = \Bbb CP^2 \# \overline{\Bbb CP^2}
$$
where the "equality" here is an orientation-preserving homeomorphism (basically just "inclusion"). But it's also true that $M'$ is homeomorphic (again by inclusion) to
$\Bbb CP^2 \# \Bbb CP^2$, by a non-orientation-preserving homeomorphism.
The trouble is that for manifolds with connected boundary $M_1, M_2$ there are two notions of connected sum:
The ordinary connected sum, denoted $M=M_1\# M_2$ where you take out open balls $B_1, B_2$ from the interiors of $M_1, M_2$ and glue $M_i-B_i$ via a homeomorphism of the new boundary spheres $\partial B_1, \partial B_2$. Then, clearly, $M$ has two boundary components, homeomorphic to $\partial M_i, i=1, 2$.
The boundary connected sum, denoted $N=M_1\#_{\partial} M_2$, where you pick two closed (tame) disks $D_i\subset \partial M_i$ and glue $M_1, M_2$ via a homeomorphism $D_1\to D_2$. Then $N$ will have connected boundary, homeomorphic to $\partial M_1 \# \partial M_2$.
(In both cases, there are some issues with the choice of gluing homeomorphisms, I will ignore these. Separately, there are issues with the category in which everything is done: TOP, PL or DIFF, in dimension 3 this does not matter.)
Thus, the answer to your question is: It depends on your notion of connected sum.
Best Answer
@DanielRust is correct; what you have constructed is just another compact manifold whose boundary is two genus-2 surfaces, not the cylinder on that surface. Here's some more detail.
$Z$ is homotopy equivalent to the two cylinders joined by line segments rather than disks. More precisely, $(X \coprod X' \coprod I_0 \coprod I_1) / R$, where each $I_j$ is a unit interval and the relation $R$ glues $0 \in I_j$ to $(t, j) \in X$ and $1 \in I_j$ to $(t, j) \in X'$ (choosing some base point $t \in T$). Using another homotopy equivalence to collapse $X$ and $X'$ to $T$ and $I_0$ to a point, we get $T \vee T \vee S^1$.
To show that $\Bbb{Z}^2 \ast \Bbb{Z}^2 \ast \Bbb{Z}$ is different from the fundamental group of the genus-2 surface, we'll need something like MO "Free splittings of one-relator groups".
Note that your construction works similarly if you replace $T$ by any manifold $M$, and some simpler examples may be helpful. If you take $M$ to be $S^1$, the result is a twice-punctured torus; if you take $M$ to be $S^2$, the result appears to be a twice-punctured $S^2 \times S^1$.