I suspect you are reading it wrong, or at least thinking of it wrong. I think you are comparing your expected annual rate of return on an investment against the total cost of borrowing of your mortgage. So comparing one year of results to thirty years of results. Of course they aren’t going to be the same.
Look at it this way - if you had $5,000 in your pocket right now, would you be better off paying down your mortgage and avoiding that 1.3% interest, or investing it and potentially earning X%.
You could use an amortization calculator and an investment calculator to get an apples to apples comparison if you like, but really you don’t need anything beyond comparing your mortgage interest rate to your anticipated rate of return. Mathematically the answer is clear. It’s when you add in risk adversion, debt adversion, psychology factors,, etc that you might tip the balance depending on your personal preferences.
Maybe someone else can lay it out a bit clearer.