He didn't write it that quickly. He had been working on it well before Lewis's death. In fact, there was a notice about it in Axios on June 16th announcing that it was coming and that Lewis was contributing an afterward to the book (which was delivered according to the cover of the book.) There were interviews earlier this year in the writing of the book which was originally slated for publication in October but the publication date was pulled forward after Lewis's death. It's also worth noting that Meacham says of the book,
"This is not a full-scale biography," Meacham explains. "It is,
rather, an appreciative account of the major moments of Lewis' life in
the movement, of the theological understanding he brought to the
struggle and of the utility of that vision as America enters the third
decade of the 21st century amid division and fear."
which implies it is not necessarily a long-term fully-researched project like some of Meacham's earlier work, although it still is extensively documented in its sources.
Every so often, a book happens to come out with coincidental timeliness, whether it's a biography that appears right around the time of its subject's death or eerily prescient plague novels or a book about Vatican politics that came out a week and a half after Pope Benedict announced he was resigning the papacy. This is one of those cases.