There are active geological processes that lead to separation of mineral constituents. A source material that contains specific primary minerals, with some transport mechanism (eg convection or liquid flows) to physically separate them and 'trapping' conditions that allow them to accumulate are all required. Processes that result in minerals being separated from the source material include -
Magmatic - (within molten and partly molten magmas). Differential melting will allow specific minerals to melt and be squeezed out separately. Differential crystallisation will allow some minerals in a mixture to crystallise within a molten mass and (with changing temperature and/or pressure) to separate and reform as crystals and precipitate separately in more concentrated form in sediments at the base of a molten mass (or to rise where they are lower density than the surrounding material). Some materials can separate in their molten state, because they are immiscible (they don't mix or dissolve within each other), with similar separation because of differing density or pressure squeezing them out and solidify in concentrated forms.
Hydrothermal - minerals dissolving (usually in association with salts), with different temperature and pressures dissolving minerals preferentially. As liquid they can travel and come into contact with other minerals, resulting in chemical reactions, with potential for further differentiation. Similar to differential crystallisation in magmas, specific minerals will crystallise and precipitate differentially out of concentrated water based solutions. Lots of sulphide mineral ore bodies were formed this way.
Physical process like erosion and sedimentation also separate and concentrate existing minerals.
(Answer in part from Wikipedia - Ore genesis).