Depends alot on the metal. Things like tin and lead are often associated with igneous rocks because they dissolve in the hot water (in this instance, hot = several hundred degrees) contained therein - that's why you get lots of lead and tin mines in cornwall, the lake district, wales and northern ireland (all of which are packed full of igneous instrusions). The same is true of undersea despoits formed near hydrothermal vents. BTW, think of an igneous intrusions as a big volcano that doesn't actually break through the surface - a big blob of hot rock that rises through the cooler rock around it (like in a lava lamp), cooking it along the way (this is how we get metamorphic rocks), plus heating up and water present, which then gets splurged out as hot springs (again, often laden with metals and minerals that dissolve in hot water). Most sulphides are formed in this manner.
Unreactive metals like gold are often formed in placer deposits - they're insoluble and often reasonably inert, and usually much denser than rock, so are often carried by water or earth until they're deposited - the textbook "panhandling" placer deposit is where at a river confluence where one fast (high energy) stream meets a low-energy stream - things suspended in the fast stream will drop to the riverbed almsot instantly, and will only be able to move by methods like saltation, hence why you often get nuggets of gold and such in mountain streams.
Then you have things like sedimentary rock that's rich in iron or other common minerals (see most sandstones, banded iron formations, etc) - this is caused by water passing through these veins of iron and it washing out to sea or dropping in a river delta, usually oxidising somewhere along the way (hence why most sands are reddy or browny, and why the extremely iron-rich Mars is known as the red planet). As Mr. Dissident said, all of the free oxygen produced by the first plant life was sucked up by minerals to produce things like BIF's.
Conversely, some ores, like bauxite, are formed by water leaching away everything *but* the aluminium, typically leaving big layers of aluminium-rich carbonates (further weathering of which can leave areas even richer in aluminium, hello Australia!).
Other metals are often "attracted" to certain types of other despoits because they're attracted (or "stuck") to types of minerals formed in other despoits.
Despoits of minerals like talc, gypsum, salt(s) and most other powdery things are usually formed by a sea or river of some sort evaporating, resulting in all of the salts crystallising out. The dead sea is a good example of a likely future salt lake (think it might be drying out already TBH).
Sandstones are rocks that are eroded into sand and then re-deposited (either by water or wind), limestones are generally formed by sea creatures made of calcium carbonate dying and dropping to the (shallow) sea floor, or by coral reefs (which themselves are just massive piles of calcium carbonate).
There's all sorts of grades in between of course, as there's almost an infinite number of possibilities of what rocks are eroded/deposited where, and what they're combined with along the way. If you can get clam fossils at the top of Everest...
And then, of course, all of the above methods are subject to any future geological wibblings.</briefhistoryofrocks>