That advice is overly simplistic. The 'best' option will vary for different people, at different times, and depending on the wider economy.
As a general rule, savings should come first - provided you're covering the basic mortgage payments and have no other debt. Once you have a reasonable amount of savings ('reasonable' can be anywhere between 3 months and a couple of years, depending on circumstances) you can think about investments that will earn more than the interest you can get in the bank.
That can be investment in the asset you live in (your house), pensions, or other investments such as stocks and shares ISAs, and potentially things like buy-to-let, vintage wines, venture capital or whatever. But let's ignore those for now.
Paying extra on the mortgage as your first choice makes emotional sense by increasing your sense of security. It makes sense in terms of medium term cash flow, by decreasing the time you're stuck with a fixed outgoing. And it can make overall financial sense if the interest you're paying on the mortgage is higher than what you could earn on savings or other investments.
So at the moment overpaying the mortgage looks reasonable if you're on a newer, rising interest rate. In the late 80s/early 90s when mortgage rates could be close to 15% and the best savings account was about 10%, and people were still skittish about stocks after the '87 crash, overpaying seemed an excellent option. But 5 years ago when you could get a mortgage for not much over 1%, it wasn't necessarily the best use of money if you could get 5% in the stock market.
So it's a matter of weighing up the return of the different options, and the other risks and benefits beyond the headline percentage.
And those other benefits are a big factor in why many people recommend pensions instead of mortgage. Long term average stock market returns are 7ish%, so you could expect roughly that growth on money in a pension (defined benefit public sector pensions are a very different animal, so I'm not including those). A bit above current mortgage rates. But when you pay money into a pension it immediately grows by at least 20% - the second it lands in the pension. More if there's an employer match, more if you're a higher rate tax payer, and more still if it's salary sacrifice so you save national insurance as well as tax. And then that money also grows.
On the downsides, unlike a house you can't live in your pension. The stock market tends to be more volatile than house prices. The money is locked away until you're at least 55, soon to be 57, whereas a repaid mortgage might free up extra spending money before that. And some of the tax saved on the way in will be paid on the way out.