By TUC, military strategists on both sides predicted an easy federation victory over the klingons.
By 'Yesterday Enterprise', the klingons had crushed the federation (the end of the war was no longer in question)*.
Meaning the federation/starfleet leadership was utterly incompetent/naively optimistic.
A probable scenario:
A large part of the fleet was mothballed after TUC (as per canon TUC, this was implied to be a serious possibility - and not contradicted).
The klingons recover from Praxis.
Starfleet training is reorganised to limit military training, to instill in starfleet personnel a distaste toward honing one's military skills.
This is made obvious in Picard, Riker's (leaders of THE top starfleet crew) behaviour from 'Peak performance'. See also Picard, Riker's airhead combat performance in episodes like 'Rascals' and others, proving they cannot use effectively the combat capabilities of their ship.
As per 'Yesterday's enterprise', the klingons killed 40 billion. You can't do that by killing merely military personnel.
Most likely, the klingons massed their forces for a surprise attack. Starfleet intelligence, as redundantly shown in canon, was/is utterly incompetent and failed to discover this.
The klingons launched their attack, destroying many federation worlds with populations numbering in the billions, eliminating large parts of the federation infrastructure.
By the time starfleet manages to mass its dispersed fleet to respond/starfleet officers manage to come up with behaviour distinguishable from utter incompetence, the klingons have a substantial advantage.
The federation is incapable of recovering during the war. Perhaps because many worlds seceded from the federation, not wanting to be the next world the klingons burn to a crisp. This is even more probable when one considers how different the cultures of the federation member worlds are.
We of course have on idea how close the Klingons were to defeat. Sure the Federation might have been six months away, but the Klingons might have been 5 weeks.
That's very true. We only know the war from Picard and his crew's POV in the episode.
Not a chance.
During war, when both parties use their assets, each side knows the situation pretty accurately. Unless the klingons had hidden reserves - which makes the situation worse for the federation.