Let $Z=\left(Z_s\right)_{s\in [0, \infty)}$ denote a continuous-time birth and death process, and $\tau_k$ is the time of the first visit to state $k$ (re-entrance of $Z$ starts in $k$).
For the expected time spent between two entrances to state $k$, why is $$\mathbb{E}_k \left[\int_{0}^{\infty}1_{\lbrace{Z_s=i, \tau_{k}>s\rbrace}}ds\right]=\int_{0}^{\infty}\mathbb{P}_{k}\left(Z_s=i, \tau_{k}>s \right)ds?$$
The closest thing that I can recall is $\mathbb{E}\left(X\right) = \int_{0}^\infty\mathbb{P}\left(X \ge x\right)dx.$
You can simplify using these steps:
$$\begin{align} \mathbb{E}_k \left[ \int_0^\infty 1_{\{Z_s=i,\tau_k>s\}}ds \right] &= \int_0^\infty \mathbb{E}_k\left[ 1_{\{Z_s=i,\tau_k>s\}}\right] ds \\ &=\int_0^\infty \mathbb{P}_k(Z_s=i,\tau_k>s) ds \end{align}$$
In the first step, we're swapping the order of integration. There are various theorems about when it's OK to do this; in this case it's justified by Tonelli's theorem since the function we're integrating is always nonnegative.
In the second step, we're just recalling that the expected value of an indicator function equals the probability that the indicator function's event will happen.