Why is it possible to separate the hydrocarbons in crude oil into fractions by distillation?

Different materials boil at different temperatures (generally and very roughly speaking, for similar molecules the lighter they are the lower the temperature at which they boil). By raising the temperature enough to boil the lighter components of a mixture but not enough to boil the heavier ones, the mixture can be separated into two "fractions", one of which is rich in lighter molecules and one which is rich in the heavier molecules.

In practice, this is generally done in "fractionating columns", where the temperature gradually decreases as you go up the column. The very lightest molecules will make it all the way to the top; slightly heavier ones will condense back into liquid a little further down, and so on. By taking out the liquid at different heights, you can separate the crude oil into many different fractions with different properties (petroleum ether, gasoline, kerosene, paraffins, etc.).