The reason you're getting the error is because one branch of the if construct defines an element of Diagonal directly from CovarianceMatrix, which is a double, but the other branch defines an element of Diagonal from the difference of CovarianceMatrix and eigval. Because eigval is a symbolic variable, the result of this calculation is a symbolic variable as well. Consequently, you're trying to assign a symbolic variable as an element of a double array. That's a type mismatch.
I don't know if this is how you want to proceed, but a simple fix is to make CovarianceMatrix a symbolic variable from the outset:
CovarianceMatrix=sym([8 -3 1;2 1 0;3 4 5]);