long story short sans killed everyone for magic so he could kill frisk to leave the underground leave the barrier unbroken so sans destory everyone on the human world instead
Credit goes to SpectralGaming.