How does one go about designing product using microcontrollers like the STM32 having a production life cycle of 10 years ?
There are no easy solutions, you need extra development work somewhere. (Assuming it is impractical to buy a lifetime supply of chips at any point.) On some projects I have done main development with similar but older chip, and port to pre-production/engineering samples as soon as they are available (help if you are a large purchaser), with the aim that volume production coincides with volume production of the target chip. That exposes you to bugs and limited quantities of the pro-prod chips, as well as delays in volume availability.
Another option is the mid-life re-spin, but obviously that relies on having an easy migration path to a similar chip, ideally there is a newer chip that is a pin-compatible replacement. Usually some software and hardware redesign is required. Probably the new design needs re-certification which is a significant exercise.
Cheap chips designed for consumer apps are attractive for the unit cost, but you really have to weigh that against development effort over the life cycle. Of course, promises of longevity are really just aspirations, no business can guarantee supply, so there is always need for contingency in the development budget to allow for component obsolescence. In some cases I have seen a product respin put out to an external design house, but that was really a last resort.
In both cases, having portable software and to whatever extent a hardware design that can migrate to different devices is essential. Avoid picking chips with special features that are only found in one manufacturer.