I tried to sketch a mathematical justification of the equality. So we have:
$$J(\tau) = E_{\tau\sim p_\theta(\tau)}[r(\tau)]$$ where $p_\theta(\tau) = p(s_1)\prod_{t = 1}^T \pi_{\theta}(a_t, s_t)p(s_{t+1}|s_t, a_t))$.
Now, $p_\theta(\tau)$ can be re-written in terms of the Markov Chain transition probabilities, namely:
$p_\theta(\tau)= \prod_{t = 1}^T \pi_{\theta}(a_t, s_t)p(s_{t}|s_{t-1}, a_{t-1})) = \prod_{t = 1}^T p(s_{t}, a_{t})$.
Here we focus on T = 2 (I guess it is not difficult to prove with a general T, maybe by induction over T). The following holds:
$$J(\tau) = E_{\tau\sim p_\theta(\tau)}[r(\tau)] = E_{(s_1, a_1, s_2, a_2)\sim p(s_1,a_1)p(s_2,a_2)}[r(s_1,a_1) + r(s_2,a_2)] \\
= \int_{(s_1,a_1)} \int_{(s_2,a_2)} (r(s_1,a_1) + r(s_2,a_2))p(s_1,a_1)p(s_2,a_2) d(s_1,a_1)d(s_2, a_2) \\
= \int_{(s_1,a_1)} \left( \int_{(s_2,a_2)} (r(s_1,a_1) + r(s_2,a_2))p(s_2,a_2) d(s_2,a_2)\right)p(s_1,a_1)d(s_1, a_1) \\
= E_{(s_1, a_1)\sim p(s_1,a_1)}\left[E_{(s_2, a_2)\sim p(s_2,a_2)}[r(s_1,a_1) + r(s_2,a_2)]\right] \\
= E_{(s_1, a_1)\sim p(s_1,a_1)} \left[E_{(s_2, a_2)\sim p(s_2,a_2)}[r(s_1,a_1)] + E_{(s_2, a_2)\sim p(s_2,a_2)}[r(s_2,a_2)] \right] \\
= E_{(s_1, a_1)\sim p(s_1,a_1)} \left[ r(s_1,a_1) + E_{(s_2, a_2)\sim p(s_2,a_2)}[r(s_2,a_2)] \right] $$
where the second line is due to the definition of the expectation, in the third line we just changed the order of the terms, in the fourth we used the definition of expectation, in the fifth we used the linearity property of the expectation and the last line is because $r(s_1, a_1)$ is constant with respect to the integration over $(s_2, a_2)$. I preferred to move to the integral form of the expectation in line two and three because it was not clear to me how exactly the expectation could factorise.
To conclude the justification, note that we defined $p(s_t, a_t) = \pi_{\theta}(a_t, s_t)p(s_{t}|s_{t-1}, a_{t-1})$, so we have another product here which can be factorised in the same way we did in line two and three of the set of equations above. This brings us the to conditional expectation form of the objective.
In general, every term we have in the original trajectory distribution $p_\theta(\tau)$ corresponds to an expectation and every reward can be moved up to the first outer expectation which it depends on.