The mirror modifier has a clipping option that you can turn on. It forces vertices at the “imaginary plane” where the mirror occurs to not cross that plane. An easy fix when this is happening is to select all vertices that should be at this plane and move then towards the plane (so if you mirror in the X direction then move the vertices towards the mirror along the x axis).
You also need to ensure you have no faces made at the mirror plane. Hope that helps.