Spectral optimization problems with internal constraint