Sans and Papyrus are parts of Gaster, from when he fell into the core and got split across time and space. They resemble two halves of Gasters Personality.
Yes, I know some people believe that this is canon to the original game, just... sigh. Deal with it okay? Thankyou.