Because Doctor Strange saw the futures.
The Russo Brothers were asked about this in Iowa City High School Q&A they did this spring.
The original, famous Reddit recap simply related
When asked why strange gave the time stone, he highly alluded to the “this is the only way” and him seeing the future scene so that basically confirmed that strange gave the stone to achieve the victory.
But more detailed quotes came out a short while later.
“Uh… Yeah, spoilers- I’m not going to say what he did but doctor strange- closure is given to doctor strange….But Doctor Strange- what did he say in the film.”
“He saw 14 Million futures, potential…futures. So maybe Doctor Strange knows something.”
Strange declared that the stone was more valuable than Tony and Peter's lives before they arrived on Titan, and more importantly, before he peered through time to glimpse the 14,000,605 possible outcomes - with only one positive possible pathway.
While he didn't divulge any details to the others, Strange's trademark pragmatism and his sudden reversal makes it fairly clear that trading the stone for Tony's life was the only way to keep on the correct pathway to victory.