That's "The Front Porch" - Episode 417.
That was all theoretical on Lily's part. She was explaining to Ted and the group her "Front Porch Test," her way of sizing up each of Ted's various girlfriends to see how well they'd fit in with the group, and pointing out how bad a match Laura Prepon's character was for Ted, and later how mismatched Ted and Robin were.
You're right that they're all old (retirement age) in the flash forwards, but I don't think we saw any actual
flash forwards to the front porch.
Here are a few screencaps, again from Netflix:
Again, here's a breakdown from Wikipedia of that episode:
Robin asks her friends if they would watch her talk show, which airs at 4:00 a.m., and the group reluctantly agrees to stay up and watch. When Ted turns up, he informs them that Karen (Laura Prepon) has broken up with him, after finding Robin's earring in Ted's bed. However, as everyone prepares to watch Robin's show, Ted discovers the matching earring of Robin's on Marshall's dresser and mutes the television to confront Marshall, believing him to have sabotaged his relationship with Karen.
As extreme events occur on Robin's show (she starts crying while showing a picture of the gang, she saves the host of the cooking segment when he catches fire, she resuscitates the weatherman after he's had a heart attack and finally she delivers a baby live on camera), still muted, Lily confesses that she has been breaking Ted up with girls who she didn't see passing the "Front Porch Test" — an indication of how they would all live together once they were old. A scene is shown of Marshall, Lily and Ted in the far future playing bridge (though clearly, none of them know how to play).
Robin returns from the show to learn the truth behind her break-up with Ted, which Lily insists she did not want to happen. Ted heads into the bar the next day to find Karen waiting, having had the situation explained to her by Lily. Karen hands Ted a letter from Lily, which contains an apology, and lets Ted know that Lily has prepared a fine dinner in Ted's apartment for him and Karen. Ted breaks up with Karen anyway after she says Ted cannot ever see Lily again and he imagines what the future would be like without her and Marshall. Returning to the apartment, Ted asks Robin to be his "plus one" and they enjoy the meal Lily prepared. They wonder whether or not they would still be together if not for Lily's intervention. Ted then makes a mock proposal to Robin, asking her to be his "backup wife". She accepts.
Meanwhile, Marshall wears a nightshirt to the pyjama party to watch Robin's show, while Barney wears a silk suit. Barney insists his clothing choice is superior, citing the possibility of attractive women coming to his home at night and seeing how good he looks, but then admits how unlikely that is and uncomfortable the "suitjamas" are. Marshall convinces Barney to try a nightshirt instead. Barney and Marshall delight in their nightshirts, having a dream about flying together in them. Barney starts wearing nightshirts to sleep. A week later, an attractive woman shows up at his apartment at night — but, upon seeing his nightshirt, she decides to leave, much to Barney's chagrin.
Having re-watched those scenes just now to make the screencaps, it's obvious in the episode itself that these are hypothetical flash-forwards from Lily and Ted's perspectives.