Good question. What you see here is the procedure known as the WKB approximation. Let's start from scratch and proceed slowly. Consider the 1D path integral given by
$$Z = \int_{-\infty}^{\infty}\exp(i\mathcal{S}/\hbar)\ \text{dx} = \int_{-\infty}^\infty\exp\left(\frac{i}{\hbar}\int_0^{t_0}\mathcal{L}(x,\dot{x})\text{dt}\right)\text{dx}.$$
Let's look at the Lagrangian closely. Suppose that the Lagrangian has the form
$$\mathcal{L}(x,\dot{x}) = \frac{1}{2}m\dot{x}^2-V(x)$$
where the potential looks like two wells stitched together. For visual sake, suppose the potential looks like
$$V(x)=\frac{1}{2}(x-L)^2(x+L)^2$$
so that when $x=L$ or $x=-L$ the potential is $V(x)=0$. Graphically, it could look like the following image posted by another physics stack exchange post.

Anyway, because of energy conservation, we know that $E=0$ but don't forget that $E=\mathcal{H}$, the Hamiltonian, and since $\mathcal{H}$ and $\mathcal{L}$ are related by
$$\mathcal{H}=\dot{x}p-L,$$
we can solve the above equation using $\mathcal{H}=0$, again we can do this because $E=0$. The above equation actually comes from the Legendre transform of $\mathcal{L}$ and you can find out more about it here. Anyway, returning to the problem we could solve the above equation to find
\begin{align}
L &= \dot{x}p\iff\\
\frac{1}{2}m\dot{x}^2-V(x)&=\dot{x}p \iff \\
-V(x) &= \dot{x}p - \frac{1}{2}m\dot{x}^2 \iff\\
-V(x) &= \dot{x}p - \frac{1}{2}\dot{x}(m\dot{x})\iff\\
-V(x) &= \dot{x}p - \frac{1}{2}\dot{x}p = \frac{1}{2}\dot{x}p\iff\\
-V(x) &= \frac{p^2}{2m} \implies \\
&\boxed{p = i\sqrt{2mV(x)}}
\end{align}
which is imaginary. Now let's go back to the path integral and plug things in to see what happens.
\begin{align}Z &= \int_{-\infty}^{\infty}\exp(i\mathcal{S}/\hbar)\ \text{dx} = \int_{-\infty}^\infty\exp\left(\frac{i}{\hbar}\int_0^{t_0}\mathcal{L}(x,\dot{x})\text{dt}\right)\text{dx}\\
&= \int_{-\infty}^\infty\exp\left(\frac{i}{\hbar}\int_0^{t_0}\left[\dot{x}p-\mathcal{H}\right]\text{dt}\right)\text{dx}=\int_{-\infty}^\infty\exp\left(\frac{i}{\hbar}\int_0^{t_0}\left[\dot{x}p-0\right]\text{dt}\right)\text{dx}\\
&=\int_{-\infty}^\infty\exp\left(\frac{i}{\hbar}\int_0^{t_0}\left[\dot{x}i\sqrt{2mV(x)}\right]\text{dt}\right)\text{dx}\\
&=\int_{-\infty}^\infty\exp\left(\frac{-1}{\hbar}\int_0^{t_0}\sqrt{2mV(x)}\frac{\text{d}x(\text{t})}{\text{dt}}\text{dt}\right)\text{dx}
\end{align}
Now from calculus, we know that the differential of $x$ is given by
$$\text{d}x(\text{t})=\frac{\partial{x(\text{t})}}{{\partial\text{t}}}\text{dt}=\frac{\text{d}x(\text{t})}{\text{dt}}\text{dt}$$
and then letting $x(t=0)=-L$ and $x(t=t_0)=+L$ we have
$$Z = \int_{-\infty}^\infty\exp\left(\frac{-1}{\hbar}\int_{-L}^{+L}\sqrt{2mV(x)}\text{dx}\right)\text{d}x = \int_{-\infty}^{\infty}\exp\left(\frac{-1}{\hbar}\mathcal{S}_{classical}\right)\text{dx}$$
Boom. The classical action pops right out.