I think the answer is yes, even if the bundles are not trivial.
Assume that $\dim X_1 < \dim X_2$. $X_1$ is a closed subset of $X$ and therefore a properly embedded submanifold. Let $Y_i=f^{-1}(X_i)$.
Let $NX_1 \subset NX_1'$ denote two nested closed tubular neighborhood of $X_1$ in $X$. There is a homotopy equivalence
$$ \text{colim} ( X_1 \xleftarrow{\pi} NX_1\setminus X_1 \hookrightarrow X_2 ) \xrightarrow{\phi} X$$
(the left hand space is the quotient of $X$ obtained by collapsing each fiber of the projection $\pi\colon NX_1 \to X_1$ to its target; the map $\phi$ stretches the fibers of $NX_1'\setminus NX_1$ to fill up all of $NX_1'\setminus X_1$).
This decomposition yields a Mayer-Vietoris sequence to compute the homology of $X$ of the form
$$
\cdots \to H_*(\nu X_1\setminus 0) \to H_*(X_1) \oplus H_*(X_2) \to H_*(X) \to \cdots
$$
where $\nu X_1\setminus 0$ denotes the total space of the normal bundle of $X_1$ in $X$ minus the zero section.
As $f$ is a submersion, it induces an isomorphism between the normal bundles of $Y_1$ and $X_1$. Moreover1 given a diffeomorphism $\nu X_1 \to NX_1$ with $NX_1$ sufficiently small, we can pick a tubular neighborhood $\nu Y_1 \xrightarrow{\cong} NY_1$ such that the square
$\require{AMScd}$
\begin{CD}
\nu Y_1 @>>> NY_1 \\
@V{Df}VV @V{f}VV \\
\nu X_1 @>>> NX_1
\end{CD}
commutes.
$f$ then induces map on the colimits which is equivalent to $f\colon Y \to X$ (in the sense that the relevant square diagram commutes up to homotopy). In terms of the Mayer-Vietoris decompositions we obtain
$\require{AMScd}$
\begin{CD}
H_*(\nu(Y_1)\setminus 0) @>>> H_*(Y_1) \oplus H_*(Y_2) @>>> H_*(Y) \\
@V{Df_\ast}VV @V{f_*}VV @V{f_*}VV \\
H_*(\nu(X_1)\setminus 0) @>>> H_*(X_1) \oplus H_*(X_2) @>>> H_*(X)
\end{CD}
It now suffices to prove that the bundle map $Df_\ast$ is an isomorphism on homology. $Df$ expresses the normal bundle of $Y_1$ as the pullback of the normal bundle of $X_1$ along the bundle projection $f\colon Y_1 \to X_1$ so for any sufficiently small open set $U\subset X_1$ which trivializes $f$ we will have that $Df \colon \nu f^{-1}(U) \setminus 0 \to \nu U \setminus 0$ induces an isomorphism. This implies that $Df_\ast$ is an isomorphism.
1 I think this statement is true in this generality but I could not find a reference or write down a complete proof. It is not hard to give a fairly explicit diffeomorphism when $f\colon Y_1 \to X_1$ is the projection of a trivial bundle as in the original question.