Cap never died. When he journeyed to return the infinity stones back to their proper timelines, his last stop was his original timeline where he got his last dance with Peggy Carter. I don't believe the movie ever disclosed the logistics behind it; it's an otherwise seemless plothole.
The movie's handle of time travel was contingent upon the multiverse theory, meaning that when they traveled back in time to get the infinity stones, their actions would have affected only those timelines and not the universe that they currently live in. It's explicitly clear this is the case during the scene when Professor Hulk retrieves the time stone. The Ancient One explains that Bruce Banner's own timeline wouldn't be affected, but the one she occupies would be "overrun." Banner goes onto explain that Dr. Strange gave Thanos the stone out of his volition and that he would return the stone immediately after saving his future timeline, to which the Ancient One then gives him the stone.
If this is indeed the movie's perception of how time works, Steve traveled to a different timeline to be with Peggy. He altered this timeline, and would not have met Falcon or Bucky on the bench in that universe. He would've had to return to the original timeline, and I'm not certain as to how this part of the plot worked.
What game will hadi.gsf want to play next?