Both technologies are used to remove something: rigid-flex removes the connector between board sections, HDI removes the area that a through-hole footprint would need. Choosing between them is a question of which constraint your device actually has.
Rigid-flex combines rigid FR-4 sections with a flex section built on a polyimide or flex laminate, bonded together in one construction. It wins when the problem is shape: a folding product, a product that must follow a curve, a wearable, or a device where a board-to-board connector has to disappear. The trade-offs are real. There are two fabrication streams and a bonding step, the rigid-to-flex transition adds thickness, and the bend region has rules — a minimum bend radius, a defined number of dynamic bends, and a requirement to keep copper and stitching away from the bend line. Static flex and dynamic flex are different specifications, and a design that folds once in a pocket is not the same problem as a design that folds ten thousand times.
HDI attacks area instead of shape. Laser microvias allow line widths and spacings that mechanical drilling cannot support, and via-in-pad structures move the interconnect close to the package. The trade-offs move to the process side: every microvia adds laser drilling time, buried or blind via stacks require sequential lamination cycles, and a design that needs a microvia everywhere pays for that everywhere. Yield per panel falls as via counts rise, and the cost is driven by the via count rather than by the layer number printed on the drawing.
The decision rule is simple. If the constraint is volume or shape, rigid-flex usually answers it with fewer layers and less exotic processing. If the constraint is density or area, HDI answers it. If a device has both — a folded enclosure containing a dense module — the answer is often a hybrid: a rigid-flex structure whose rigid sections carry microvias, which gets the mechanical shape and the escape density at once. Whichever route is chosen, the mechanical stack must be drawn early, because the transition thickness, the bend envelope and the assembly fixtures all follow from the structure decision rather than from the schematic.