Regularity of the optimal sets for some spectral functionals