Trouble with Gaussian Mixture Model

I got it work mostly. There are times when L is still not identifiable but mu is identified. The issue with your model was that the ordering of mu needed to be switched the way you had it. I switched that around and put a hyper prior on the normal distribution for mu (coded as p). I also transformed theta to an unconstrained space which helps the estimation.

data {
  int D; // number of dimensions
  int K; // number of gaussians
  int N; // number of data
  vector[D] y[N]; // data
}

parameters {
  vector[K] theta_raw; // mixing proportions
  ordered[K] mu_raw[D]; // mixture component means
  positive_ordered[K] p;
  cholesky_factor_corr[D] L[K]; // cholesky factor of covariance
}
transformed parameters{
  simplex[K] theta = softmax(theta_raw);
  vector[D] mu[K];

  for (d in 1:D){
    for (k in 1:K){
    mu[k, d] = mu_raw[d, k];
    }
  }
}
model {
  real ps[K];
  
  p ~ normal(0, 3);
  for (k in 1:K) {
    for (d in 1:D) mu[k, d] ~ normal(p[k], 3);
    L[k] ~ lkj_corr_cholesky(4);
  }
  theta_raw ~ normal(0.0, 0.5);

  
  for (n in 1:N) {
    
    for (k in 1:K) {
      //increment log probability of the gaussian
      ps[k] = log(theta[k]) + multi_normal_cholesky_lpdf(y[n] | mu[k], L[k]);
    }
    
    target += log_sum_exp(ps);
  }
}

Call to R

fit <- rstan::stan('stan_help.stan',
            data = mixture_data,
            chains = 2,
            cores = 2,
            control = list(adapt_delta = 0.98, max_treedepth = 12),
            iter =  1000,
            seed = 221
)

Output

                 mean se_mean   sd    2.5%     25%     50%     75%   97.5% n_eff Rhat
theta_raw[1]   -0.01    0.01 0.30   -0.62   -0.20   -0.02    0.19    0.54   525 1.00
theta_raw[2]    0.02    0.01 0.31   -0.57   -0.21    0.03    0.22    0.63   710 1.00
theta_raw[3]    0.00    0.01 0.30   -0.58   -0.21    0.00    0.20    0.60   600 1.00
mu_raw[1,1]     0.04    0.01 0.18   -0.35   -0.08    0.05    0.16    0.39   320 1.00
mu_raw[1,2]     2.94    0.01 0.19    2.56    2.82    2.94    3.06    3.34   446 1.00
mu_raw[1,3]     5.99    0.01 0.19    5.62    5.87    5.99    6.11    6.36   540 1.00
mu_raw[2,1]     0.02    0.01 0.18   -0.33   -0.10    0.01    0.13    0.39   284 1.00
mu_raw[2,2]     2.96    0.01 0.20    2.53    2.83    2.96    3.09    3.33   444 1.00
mu_raw[2,3]     6.10    0.01 0.18    5.73    5.98    6.10    6.23    6.45   603 1.00
mu_raw[3,1]     0.03    0.01 0.18   -0.34   -0.10    0.03    0.15    0.38   292 1.01
mu_raw[3,2]     2.92    0.01 0.20    2.53    2.80    2.92    3.04    3.32   435 1.00
mu_raw[3,3]     6.04    0.01 0.19    5.67    5.90    6.04    6.16    6.41   504 1.00
mu_raw[4,1]    -0.04    0.01 0.18   -0.39   -0.16   -0.04    0.07    0.31   335 1.00
mu_raw[4,2]     2.94    0.01 0.20    2.54    2.81    2.95    3.08    3.32   408 1.00
mu_raw[4,3]     5.88    0.01 0.19    5.52    5.75    5.88    6.00    6.24   536 1.00
p[1]            0.86    0.02 0.68    0.03    0.32    0.70    1.27    2.51   798 1.00
p[2]            2.53    0.04 1.03    0.69    1.77    2.53    3.25    4.58   784 1.00
p[3]            5.06    0.04 1.20    2.92    4.23    5.04    5.84    7.55  1108 1.00
L[1,1,1]        1.00     NaN 0.00    1.00    1.00    1.00    1.00    1.00   NaN  NaN
L[1,1,2]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,1,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,1,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,2,1]       -0.73    0.05 0.36   -0.92   -0.88   -0.84   -0.77    0.67    59 1.03
L[1,2,2]        0.57    0.01 0.13    0.38    0.47    0.54    0.64    0.95   118 1.02
L[1,2,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,2,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,3,1]        0.01    0.17 0.69   -0.85   -0.73    0.16    0.71    0.86    16 1.09
L[1,3,2]       -0.14    0.05 0.33   -0.71   -0.38   -0.18    0.11    0.52    36 1.04
L[1,3,3]        0.62    0.00 0.12    0.43    0.54    0.61    0.69    0.89   815 1.00
L[1,3,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[1,4,1]       -0.03    0.21 0.73   -0.87   -0.76   -0.39    0.77    0.88    12 1.11
L[1,4,2]        0.11    0.06 0.32   -0.51   -0.15    0.17    0.35    0.68    29 1.05
L[1,4,3]       -0.21    0.02 0.22   -0.60   -0.35   -0.24   -0.10    0.26    81 1.02
L[1,4,4]        0.49    0.00 0.09    0.35    0.43    0.48    0.55    0.72   408 1.00
L[2,1,1]        1.00     NaN 0.00    1.00    1.00    1.00    1.00    1.00   NaN  NaN
L[2,1,2]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,1,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,1,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,2,1]        0.61    0.18 0.51   -0.88    0.70    0.79    0.84    0.90     8 1.24
L[2,2,2]        0.60    0.01 0.11    0.42    0.52    0.58    0.67    0.85   428 1.00
L[2,2,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,2,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,3,1]        0.90    0.00 0.04    0.79    0.88    0.91    0.93    0.95   601 1.00
L[2,3,2]        0.15    0.03 0.14   -0.20    0.09    0.17    0.23    0.40    22 1.08
L[2,3,3]        0.38    0.00 0.07    0.28    0.33    0.37    0.42    0.54   791 1.00
L[2,3,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[2,4,1]        0.68    0.18 0.49   -0.84    0.79    0.85    0.88    0.92     7 1.27
L[2,4,2]        0.31    0.01 0.14    0.08    0.23    0.30    0.39    0.60   528 1.01
L[2,4,3]        0.00    0.02 0.11   -0.23   -0.07    0.00    0.07    0.20    53 1.03
L[2,4,4]        0.41    0.00 0.07    0.30    0.36    0.40    0.45    0.58   872 1.00
L[3,1,1]        1.00     NaN 0.00    1.00    1.00    1.00    1.00    1.00   NaN  NaN
L[3,1,2]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,1,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,1,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,2,1]        0.41    0.19 0.68   -0.87    0.02    0.78    0.84    0.90    13 1.14
L[3,2,2]        0.60    0.01 0.12    0.43    0.52    0.59    0.67    0.91   506 1.01
L[3,2,3]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,2,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,3,1]       -0.28    0.56 0.75   -0.91   -0.85   -0.77    0.74    0.88     2 2.18
L[3,3,2]        0.05    0.18 0.29   -0.46   -0.19    0.09    0.26    0.53     3 1.31
L[3,3,3]        0.51    0.00 0.10    0.36    0.44    0.49    0.56    0.76   612 1.01
L[3,3,4]        0.00     NaN 0.00    0.00    0.00    0.00    0.00    0.00   NaN  NaN
L[3,4,1]       -0.39    0.42 0.70   -0.91   -0.86   -0.81    0.55    0.84     3 1.58
L[3,4,2]        0.02    0.14 0.26   -0.43   -0.18    0.01    0.22    0.52     3 1.19
L[3,4,3]        0.28    0.02 0.15   -0.02    0.19    0.27    0.37    0.59    48 1.02
L[3,4,4]        0.43    0.01 0.08    0.30    0.37    0.42    0.47    0.61    98 1.03
theta[1]        0.33    0.00 0.05    0.24    0.30    0.33    0.36    0.43  1396 1.00
theta[2]        0.34    0.00 0.05    0.25    0.30    0.34    0.37    0.44  1308 1.00
theta[3]        0.33    0.00 0.05    0.25    0.30    0.33    0.37    0.43  1269 1.00
mu[1,1]         0.04    0.01 0.18   -0.35   -0.08    0.05    0.16    0.39   320 1.00
mu[1,2]         0.02    0.01 0.18   -0.33   -0.10    0.01    0.13    0.39   284 1.00
mu[1,3]         0.03    0.01 0.18   -0.34   -0.10    0.03    0.15    0.38   292 1.01
mu[1,4]        -0.04    0.01 0.18   -0.39   -0.16   -0.04    0.07    0.31   335 1.00
mu[2,1]         2.94    0.01 0.19    2.56    2.82    2.94    3.06    3.34   446 1.00
mu[2,2]         2.96    0.01 0.20    2.53    2.83    2.96    3.09    3.33   444 1.00
mu[2,3]         2.92    0.01 0.20    2.53    2.80    2.92    3.04    3.32   435 1.00
mu[2,4]         2.94    0.01 0.20    2.54    2.81    2.95    3.08    3.32   408 1.00
mu[3,1]         5.99    0.01 0.19    5.62    5.87    5.99    6.11    6.36   540 1.00
mu[3,2]         6.10    0.01 0.18    5.73    5.98    6.10    6.23    6.45   603 1.00
mu[3,3]         6.04    0.01 0.19    5.67    5.90    6.04    6.16    6.41   504 1.00
mu[3,4]         5.88    0.01 0.19    5.52    5.75    5.88    6.00    6.24   536 1.00
lp__         -384.51    1.06 5.08 -395.27 -387.75 -384.16 -380.82 -375.99    23 1.06