Different elements have different chemical and physical properties (and on Earth, different biological properties) As atoms with the same or similar properties tend to move the same way, there is sorting. This happens on all sorts of levels.
Volatile elements, especially light novel gas like Helium or Neon, will get sorted from heavier elements by the action of the solar wind in the early formation of terrestrial planets.
Elements can be classed as siderophile, lithophile, chalcophile, or atmophile. They are sorted when the planet is forming and is largely, or completely molten. The "iron-loving" siderophile elements sink to the core. The "ore-loving" elements are found in the mantle. The "rock-loving" elements are found in the mantle and crust, and the atmophile elements in the atmosphere. Different minerals crystalise at different temperatures, so you get separation of minerals.
Chemical properties further sort the elements, for example chlorine will react preferentially with sodium, and the resulting salt is very soluble, so will tend to migrate to the ocean.
And on Earth, biology plays a major role, for example it moves carbon out of the atmosphere and into the biosphere, and from there, to the crust.
This happens over and over on every scale: volcanos pull chalcophile elements from the mantle, but as they are chemically different from the lithophile elements in the crust, they will tend to group together, forming deposits of ores. These deposits might be formed after several stages of erosion/deposition, in each cycle the sorting repeats, resulting in the ore becoming more refined.
A planet is like a big box of muesli; as you shake it, the nuts and fruit will separate from the oats, as a result of their different properties. An increase in entropy can result in separation, not mixing.