There were at least a hundred hints that that's where they were heading.
Ted starts with the story of how he met Robin, not the mom. Why? Because this isn't a story about the mom. It's about Robin.
Ted talks to his kids about meeting the mom, but the mom isn't there. Why? Because she's no longer there to tell her side of the story.
The kids are enrapt by this very long story no kids want to hear about their parents. Why? Because the only way they can know their mom is through their dad's long boring stories.
The mom's story starts with her talking to the spirit of her late boyfriend, asking him if it's okay to get married to someone else. Why? Because that's what Ted is doing, asking the spirit of his wife through their kids if it's okay to date (and probably marry) Robin.
Heck, Ted and the mom look sadly at each other when one of them says, "What kind of mom would miss her own daughter's wedding?" because they both know she's not going to live long enough to see their daughter get married.
And there are like a hundred other clues.
You clearly weren't watching the same show I was if you thought it was going to end any other way.