A bain-marie is built from two nested vessels rather than one. The outer vessel holds water and sits over the actual heat source, whether an open flame, coals, or a modern stove burner, while the inner vessel, holding whatever substance is being warmed, sits inside that water rather than touching the fire directly.
Heat travels from the flame into the water first, and the water itself acts as a buffer: because water cannot rise above its boiling point no matter how hard the fire underneath burns, the inner vessel can never be exposed to a heat any higher than boiling water can deliver, which caps the temperature automatically without the operator having to watch a fire and guess. That ceiling made the bain-marie the tool of choice whenever a substance would scorch, curdle, or decompose under direct flame but still needed steady warmth, whether that substance was a delicate alchemical extract, a sauce that would split if it touched a hot pan directly, or a solution that needed to dissolve or digest slowly rather than boil violently. The setup also evens out temperature far better than direct heat, since the water circulates around the inner vessel and carries heat to every part of it at roughly the same rate, avoiding the hot spots a pot sitting straight on a flame develops wherever the flame happens to touch hardest.