A CD is guaranteed to pay its return on maturation. So if you need a certain amount of money at a specific time in the future, the CD is a more reliable way of getting it. The stock market might give you more money or less. More is obviously OK. Less is not if you're planning to pay basic expenses with it, e.g. food, rent, etc.
Most retirement portfolios will have a mix of investments. Some securities (stocks and bonds), some guaranteed returns (CDs, treasuries), and some cash equivalents (money market, savings, and checking accounts). Cash equivalents are good for short term expenses and an emergency fund. Guaranteed returns are good for medium term expenses. Securities are good for the long term.
Once retired, the general system is to maintain enough cash equivalents for the next few months of expenses and emergencies. Then schedule CDs for the next few years so that you have a predictable amount. Finally, keep the bulk of your wealth in securities. As you get older, your potential emergencies increase and your need for savings decreases, so the mix shifts more and more to the cash equivalents and guaranteed returns and away from securities.
CDs have limited use prior to retirement (and the couple years right before retirement), mainly saving up for a large purchase like a house, car, or major appliance. Even there if you have the option of delaying the purchase, that might allow you to use securities instead. Perhaps some of your emergency fund in a short term CD that you keep rolling over.
Note that the problem isn't so much that securities will fall. It's that they'll fall right when you need the money. So rather than sell 1% of your securities to meet your needs, you have to sell 2%. That's a dead weight loss of 1% that you have to deduct from your returns. That roughly matches the drop from the height of 2007 to the trough of 2009 of the S&P 500. And it was 2012 before it recovered. If in 2007, you had put the 1% of your portfolio in a two-year CD, you'd be ahead even at zero interest in 2009.