But you are ignoring risk. Over the 20 year period your annual returns fluctuated. Take, for example, a “made up” index that lost 54% in 1998 and its subsequent returns were those of the S&P500 for that period. By the end of 2017 your capital sum has returned to its original amount, but in the period concerned your returns have fluctuated with a standard deviation of about 21%. This is real risk you have taken on and for which you have not been rewarded. If you assume a risk free rate of about 2.75% on a long duration bond, you've a negative Sharpe ratio of about -13%. You have not made a wise investment as you have not been rewarded for the market risk you have taken on. It's not just that you get your capital sum back , it's that you get your capital sum back and also are rewarded for taking on market risk. Otherwise you put your savings directly in governtemn bonds or analogues.
But let's assume what you say is correct, and that investing for 20 periods does not result in a capital loss. This implies long duration investing is equivalent to buying a bond that will deliver a capital sum equal to your original investment after 20 years (or whatever your selected time period). If this were true, it has happened only because at the start of the 20 years period, stocks were priced to deliver returns the sum of which are equal to your initial investment over the period concerned. If the price at purchase is higher you have a longer duration to wait for the accumulated returns equal your initial investment and if the price is lower your duration is shorter. The 'price' of a stock market is its price/dividend ratio. If you assume the dividend rate is constant, the price of the index must also grow at the same rate as dividends over the period concerned. Currently, for the S&P the dividend yield is 1.84% (end 2017)
http://www.multpl.com/s-p-500-dividend-yield/table, so the price/dividend is about 42, which implies a holding period of in excess of 40 years as of today. So those starting out investing today, and only these people, should be totally invested in stocks, as current prices imply a risk free investment, if you hold until you retire.