This looks to be a version of the probability chain rule. Since $f(y, a_0, z, a_1) = f(y | a_0, z, a_1) \times p(a_1 | z, a_0) \times p(z | a_0) \times p(a_0)$. You can divide through by the last twothree terms in my equation to arrive at your equation.
https://en.wikipedia.org/wiki/Chain_rule_%28probability%29#More_than_two_random_variables