Most succulents flower when they are mature and conditions have been favourable — enough light, a cool dormant period, and a plant old enough to spare the energy. In those cases a flower spike is a compliment.
A smaller group behaves differently, and for them the flower is the end of the plant's life rather than a milestone in it.

Monocarpic species
Some succulents are monocarpic: they grow for years, flower once, set seed, and die. It is not a failure of care and there is nothing to be done about it — it is the species' reproductive strategy.
Sempervivum, commonly sold as houseleek or hens-and-chicks, is the best known. The main rosette produces a tall stalk, flowers, and then dries up. Several agaves do the same after many years, and a number of aeoniums behave that way rosette by rosette.
The good news is that these species almost always produce offsets long before they flower.

The parent dies; the pups continue. So the practical response to a flowering sempervivum is not to try to save the rosette but to make sure the offsets around it are healthy and have somewhere to grow. Separate them once they have their own roots, pot them individually in gritty mix, and the plant carries on as a colony even though that particular rosette does not.
Species where flowering is simply good
Echeveria, sedum, kalanchoe, haworthia, aloe and most crassula flower repeatedly and carry on afterwards. A flower spike from any of those means the plant is mature and has been given decent light and a cool enough winter to trigger it.
The one consideration is that flowering costs energy. On a plant that is small, recently repotted, or recovering from a problem, it is reasonable to cut the spike off so the plant puts its resources into leaves and roots instead. On a large healthy plant there is no reason to.
What usually triggers it
Bright light through the growing season is the main requirement, and it is the thing most indoor succulents lack. A plant that has never flowered on a north-facing sill will often flower in its first year on a south-facing one.
A cool, dry rest through winter matters for many species — a period at 10 to 15 °C with very little water is what initiates flowering in spring for echeveria and several others. A plant kept warm and watered all year round often stays healthy and never flowers.
Age matters too. Most species need to be several years old, and a young plant that is not flowering is not doing anything wrong.
Aftercare
Once the flowers have faded, cut the spike back to its base with a clean blade. Leaving it does no harm but the plant will not reuse it.
Expect a pause afterwards. A plant that has just flowered often produces little new growth for a month or two while it rebuilds, and that lull is normal rather than a sign that something went wrong.
If seed is of interest, a flowering succulent is the only opportunity to collect it, and hand-pollinating with a small brush between two flowers of the same species is straightforward. It is worth knowing that seedlings from a hybrid rarely resemble the parent.
Telling a flower spike from an offset early
Both emerge from around the centre or the base of a rosette, and for the first week or two they can look similar. A flower spike grows fast, is noticeably more slender than the leaves, and elongates rather than widening. An offset stays compact and immediately begins forming a miniature rosette of its own.
The distinction matters mostly for monocarpic species, where the appearance of a spike means it is time to make sure the offsets are secure rather than time to celebrate.
Etiolation looks like a spike and is not
A succulent stretching for light produces a long stem with widening gaps between leaves, and people often mistake the early stage for a flower stalk. The difference is that stretched growth carries normal leaves along its length at increasing intervals, while a flower spike is bare for most of its length and carries buds at the top.
If what is rising from the centre has leaves on it and the plant is also leaning toward a window, the answer is more light rather than a coming flower. That plant will not compact again on its own — the usual remedy is to behead the rosette, let the cut callous for a few days, and root it in dry gritty mix while the stump produces offsets.
