Possible answer: Because he hates Trump?
This is assuming Esper quit, but Trump fired him first. If he wanted to hurt Trump, why not quit before the election to make problems? If he didn't want to hurt Trump, why quit with 72 days left? The job is over. Staying during transition and ensuring a smooth transfer should be in Esper's best interests professionally and is best for the country.
Trump could’ve thought firing Esper would reflect badly on him come elections.
Esper is likely to work for defense contractors who are mostly republican, thus wouldn’t want to be seen as hurting the reelection
Why with 72 days left? DoD shouldn't be on Trump's radar right now. What does Trump have planned over the next 2 months that this move would make a difference? That NY Times piece is what I'd be looking for.
Esper went against Trump with using the military on the streets of the US. Trump gets rid of anyone that disagrees. That is a very dangerous person when QAnon is his source for information.
If Trump got rid of everyone who disagrees, he'd be down to half his staff, especially now, when they have nothing to lose by voicing dissent. This is SECDEF. There's more here.