Most spices are oil soluble. Some spices, notably those with phenols, are more soluble in water than others, but almost all will lend their flavor to oils better and faster than water. Generally, if you want to infuse a dish with the flavor of herbs or spices, the dish will need to have some fat content to get it to absorb the flavoring chemicals.
Steam is not carrying away the flavoring compounds in spices. The chemicals that give herbs and spices their flavor are more volatile than water. They are not dissolved in the steam, because many of the chemicals do not dissolve easily in water. They are evaporating away separately, and can be doing so before the water in a dish begins to boil.
For prolonged cooking, it depends on the herb/spice, the temperature, the pressure/environment, and the time it is cooking. For example, an herb like parsley has a light and delicate flavor. If it is cooked, dried, or heated, the flavor will quickly dissipate because the flavoring compounds are very volatile and will quickly evaporate. This is why most people use fresh chopped parsley, added at the end of cooking. An herb like rosemary will have more compounds that are less volatile, and the leaves themselves have more structural integrity, which holds those compounds inside the leaf longer. Thus, rosemary tolerates longer cooking and higher temperatures, and because many of the volatile flavoring compounds are locked inside of those robust cells, its flavor becomes enhanced by cooking it (or crushing or chopping it), which breaks down the cell walls and releases the flavoring compounds.