A glued Riemannian space is obtained from Riemannian manifolds $M_1$ and $M_2$ by identifying their isometric submanifolds $B_1$ and $B_2$. A curve on a glued Riemannian space which is a geodesic on each Riemannian manifold and satisfies certain passage law on the identified submanifold $B:=B_1 \cong B_2$ is called a $B$-geodesic. Considering the variational problem with respect to arclength $L$ of piecewise smooth curves through $B$, a critical point of $L$ is a $B$-geodesic. A $B$-Jacobi field is a Jacobi field on each Riemannian manifold and satisfies certain passage condition on $B$. In this paper, we extend the Morse index theorem for geodesics in Riemannian manifolds to the case of a glued Riemannian space.