It depends on the size of the asteroid. For something the size of the Earth or moon, where gravity is generated, a molten mass will differentiate with heavier metals descending to the center and lighter material migrating to the crust. It would still be a "rough sort", elements of similar mass might not be able to separate into clean layers.
You can't just spin the asteroid, it will fly apart.
For small asteroids of "mining" size, the gravity will be too slight, even when molten, to separate like that. Elements won't overcome surface-tension and viscosity enough to move.
A more likely mining scenario is to melt the asteroid parts and introduce them to a centrifuge, where with spin you can apply hundreds or thousands of centrifugal gravities until the molten parts cool into very distinct layers.
You can make the centrifuge out of tungsten, the metal with the highest melting point (6192F) and highest tensile strength.
You might want to start the heating slowly, so you can capture some of the elements released by heating; they will be the first to liquefy and then vaporize. This is basically a form of distillation: Alcohol has a boiling point of 173F, water is 212, so if you heat a mixture of alcohol and water to about 190F, the "steam" vapor contains much more alcohol than water; and this can be repeated a few times to extract nearly pure alcohol (95.5%) from a fermented mash. (See azeotrope for details of why it can't get more pure without more complex methods, like pressurization or other ingredients).
By heating the asteroid slowly, increasing the temperature a few degrees at a time, we can do a similar thing, capturing elements that vaporize at different temperatures.
Slower heating will also help to prevent explosions. For the latter, first cold-grinding the asteroid to sand-size bits will help as well, breaking any large pockets of frozen gas or water trapped in the rock.
All of this can be done with concentrated solar energy, as a typical scenario for actually mining asteroids, for everything from oxygen to heavy metals (precious or not). One of the good products of asteroid mining is iron, for construction steel, which is very expensive to lift from a planet surface, but practically free if mined in space using giant mirrors to focus the sun.
Edit: Note that in micro-gravity space, these can be many paper-thin polished aluminum parabolic mirrors, a hundred yards in diameter with quite minimal support to provide all the power necessary. They can also be used to drive either photo-voltaics or Stirling engines to generate electrical power, which is useful both for the habitats and further distillation or breaking of compounds by electrolysis (like separating water into hydrogen and oxygen).
Edit: Once the molten asteroid cools in the centrifuge; you will have a wheel of layers of rings. For further processing, you would peel (or grind) the layers off. At the boundaries where two materials mix, you can direct the grind to a separate catch-bin, when you have enough of that you can re-melt, re-centrifuge, and do this again, grind off the pure parts and leave any mixed part in the catch-bin. The point being, you don't have to be razor accurate in separating the rings in order to have a pure product.
Edit: For fun, here is a nice wiki page that lets you sort the elements by melting-point or boiling-point, to help you see the order in which you can retrieve them. Of course some will be bound in compounds; typically lowering their melting/boiling point.
Edit on Feasibility: On the mirrors: At the distance of the middle of the asteroid belt (400 million km), there is about 190 Watts per square meter of solar radiation to be captured (barring shadows). (Compare to Earth, 1370 W/$m^2$ hits our upper atmosphere, about half makes it through the air to the surface.)
So a single 100 meter diameter parabolic mirror could focus 1.5 MW of power on a "point" (IRL perhaps 50 centimeters wide). But we can have hundreds or thousands of these focused on a single point. Space has plenty of space!
EDIT: For cooling, note Stirling engines are heat pump engines that can also cool things; but in general the trick to cooling the molten mass is to make the heat do some kind of physical work. A steam engine is a primitive example of this. (There are closed cycle steam engines and Stirling engines, BTW, that could be engineered to work in a vacuum). Trivially it could be used to help heat the miner's habitat; but also for mechanical tasks like cold-grinding asteroids to a powder and grinding previously cooled wheels of separated ore, compressing gases back to liquid, making electricity for atomic accelerator propulsion, etc.