Interplay between the spin state of manganese and the stability of the crystal structure of MnAs and MnP compounds