should be
log_lik[n] = beta_binomial_lpmf(Y[n] | 22, p[n] * phi, (1-p[n]) * phi);
The way I figured where the problem is that I checked the log_lik values. For discrete model with uniform probability for 22 categories lpmf would be \log(1/22)\approx -3.1, but lpmf’s from your code were around -461, so the were clear two orders of magnitude error in log scale! With the fixed code mean lpmf is about -2.3>-3.1, ie the model is beating the uniform distribution. loo works fine.