Preliminaries
I'll assume a finite state space $\mathcal{S} = \{s_1, \dots, s_m\}$. Let $X_t$ be a random variable representing the state at time $t$, and let $x_t \in \mathcal{S}$ denote a particular realization of this random variable. Transition probabilities are given by $m \times m$ stochastic matrix $P$, where $P_{ij}$ gives the probability of transitioning from state $s_i$ to state $s_j$ in a single timestep. I'll assume the Markov chain is time-homogeneous, so the transition probabilities are constant across time.
Answer
The question is essentially asking for the conditional distribution of the intermediate states $X_1, \dots, X_{k-1}$, given known initial state $X_0=x_0$ and final state $X_k=x_k$. By the definition of conditional probability, this is:
$$p(x_1, \dots, x_{k-1} \mid x_0, x_k) \ = \
\frac{p(x_0, \dots, x_k)}{p(x_0, x_k)} \tag{1}$$
Note that the numerator in $(1)$ can be rewritten as $p(x_1, \dots, x_k \mid x_0) p(x_0)$ and the denominator as $p(x_k \mid x_0) p(x_0)$. Substituting these in, the $p(x_0)$ terms cancel and we can rewrite $(1)$ as:
$$p(x_1, \dots, x_{k-1} \mid x_0, x_k) \ = \
\frac{p(x_1, \dots, x_k \mid x_0)}{p(x_k \mid x_0)} \tag{2}$$
The numerator and denominator in $(2)$ can be calculated as follows.
The numerator
The numerator $p(x_1, \dots, x_k \mid x_0)$ is the probability of the sequence $x_1, \dots, x_k$ following starting state $x_0$. Recall that, for a Markov chain, this is given by:
$$p(x_1, \dots, x_k \mid x_0) = \prod_{t=1}^k p(x_t \mid x_{t-1}) \tag{3}$$
where the transition probabilities $p(x_t \mid x_{t-1})$ are specified by the transition probability matrix $P$.
The denominator
The denominator $p(x_k \mid x_0)$ is a normalizing constant, representing the probability of ending in state $x_k$ after $k$ time steps, given that we start in state $x_0$. Recall that $k$-step transition probabilities for a Markov chain are given by $P^k$, the $k$th power of transition probability matrix. The $(i,j)$th element of this matrix gives the probability of ending in state $s_j$ after $k$ timesteps, given that we start in state $s_i$. Therefore, if $x_0 = s_i$ and $x_k = s_j$:
$$p(x_k \mid x_0) = (P^k)_{ij} \tag{4}$$