Avengers: Endgame co-writers Stephen McFeely and Christopher Markus knew from the start how they wanted Captain America's story to end, even before they knew they had the job for Endgame. While working on Cap's origin story during Captain America: The First Avenger the co-writers had the ending in mind even though Endgame was years away with no confirmed writers for the script.
Steve Rogers had the classic arc of an American hero from the very beginning. During Captain America: The First Avenger, the audience was led on a journey of a sickly kid from Brooklyn who was unafraid of standing up for what he believed in. The man who became Captain America didn't necessarily require a super serum to act heroic, but it was clear from the start that Steve Rogers was willing to sacrifice himself for the greater good. His arc leading up to Endgame continued to show Cap's growth as a man worthy of wielding Mjolnir as well as a man finally allowing himself to act selfish and live a normal life with the woman he loves.
Mcfeely and Markus spoke to Vanity Fair at length about their own journey contemplating Cap's arc from the moment they co-wrote The First Avenger way back in 2011, and how they knew the audience expectations for the original Avenger's happy ending would be a recurring theme for future MCU movies.
"At the very end of [2011’s] The First Avenger, when Steve misses the dance with Peggy, you start going, I wonder if there’s going to be a way to get those two together...even though 70 years has passed."
While Markus and McFeely were confident from the start how they wanted Cap's story to reach full circle, they were careful to note that they only started writing Endgame four years before the premiere, after they had been officially been hired by the head of Marvel Kevin Feige after working on the script for Captain America: Civil War. "We got the job as we were prepping Civil War. So that meant that Kevin Feige, the head of Marvel, had hired me, Chris, and [directors] Joe and Anthony Russo simply based on The Winter Soldier, to do both the Avengers movies." The co-writers had proven themselves worthy of Captain's America's ongoing arc, and their scripts meshed well with the Russo brothers' direction.
When all is said and done, Cap's somewhat controversial choice to stay back in time to live his life with Peggy made perfect sense given his journey leading up to that moment. Markus and McFeely clearly invested a lot of time and thought in their choices for wrapping up the story of the first Avenger, a hero America and the world believed in and who gave his all to the very end of Avengers: Endgame. The choice to hire the two writers to bring the epic Infinity War saga was a wise one, and in a way hiring the writers that began in Phase One of the MCU to bring Phase 3 to a close was a great full circle moment for the Marvel Universe. Audiences were rooting for Captain America to get his happy ending after all he had been through and while some were surprised when he actually took the chance for it himself, it made perfect sense as a coda to the character's story. Cap was a hero worthy of wielding the God of Thunder's hammer and also deserving of his own happy ending.
Source: Vanity Fair