Even if the distribution parameters are outputs of a network, sampling is not a mathematically differentiable operation (it is not even a function). Depending on your use case, you might want to look into divergence metrics like KL or use the reparametrization trick from VAE by inputing a random noise to the network.