I'm assuming you're talking about WWI.
The answer is that Erich von Ludendorff, who headed the OHL and was quasi-dictator of the country by then was of the opinion that the army would collapse any day and he feared that they would bring revolution back home in that case.
He wanted to save the army's face and honour and he wanted to prevent a revolution breaking out. He basically told the foreign minister, Emperor and chancellor that he could no longer guarantee the army to hold out and he recommended a drastic reform of the constitutional system of Germany along Woodrow Wilson's 14 Points, in order to get a less-harsh peace. He figured that, if one could appease the USA, they would in turn not let France put on too harsh conditions for peace.
Changing the structures of government was also very convenient for him for another reason. By letting liberal and social-democrat politicians into the government, they would have to sign the armistice, for example. This was later used by anti-republican forces to brand the new republic a country founded by "November-Criminals" in the "Stab-in-the-Back Myth". This is all very nicely summed up by Generaloberst Albrecht von Thaer in his memoirs:
Er sagte ungefähr folgendes: Er sei verpflichtet, uns zu sagen, daß unsere militärische Lage furchtbar ernst sei. Täglich könne unsere Westfront durchbrochen werden ... Auf die Truppe sei kein Verlaß mehr ... So sei vorrauszusehen, daß dem Feinde schon in nächster Zeit mit Hilfe der kampffreudigen Amerikaner ein großer Sieg, ein Durchbruch in ganz großem Stile gelingen werde, dann werde dieses Westheer den letzten Halt verlieren und in voller Auflösung zurückfluten über den Rhein und werde die Revolution nach Deutschland tragen. Diese Katastrophe müsse unbedingt vermieden werden. Aus den angeführten Gründen dürfe man sich nun nicht mehr schlagen lassen. Deshalb habe die OHL von S.M. und dem Kanzler gefordert, daß ohne jeden Verzug der Antrag auf Herbeiführung eines Waffenstillstandes gestellt würde bei dem Präsidenten Wilson von Amerika zwecks Herbeiführung eines Friedens auf der Grundlage seiner 14 Punkte.
[...]
Exc. Ludendorff fügte hinzu: 'Zur Zeit haben wir also keinen Kanzler. Wer es wird, steht noch aus. Ich habe aber S.M. gebeten, jetzt auch diejenigen Kreise an die Regierung zu lassen, dene wir es in der Hauptsache zu danken haben, daß wir so weit gekommen sind. Wir werden also diese Herren jetzt in die Ministerien einziehen sehen. Die sollen jetzt den Frieden schließen, der jetzt geschlossen werden muß. Sie sollen die Suppe jetzt essen, die sie uns eingebrockt haben!'"
__
He said about the following: He was obliged to tell us that our military situation was terribly serious. Any day our Western Front could be broken through ... This Army could not be trusted any longer ... So it was foreseeable that the enemy may succeed in a great victory, a breakthrough of biggest proportions. Then, this Western Army would lose its foothold and flood back over the Rhine, in full dissolution and carry the revolution into Germany. That catastrophe would have to be be avoided at all costs. Because of the mentioned reasons we could not lose another fight now. This is why the OHL demanded of His Majesty and the chancellor that without any delay the bid for the making of peace towards President Wilson of the USA, in order to create peace according to his 14 Points had to be made.
[...]
His Excellency Ludendorff added: 'As of now we do not have a chancellor [after hearing the news, the last one resigned]. Who will become next one remains to be seen. However, I have asked His Majesty to now also let those circles into the government that we have mainly to thank for for it coming this far. So we will now see these gentlemen march into the ministries. Let them make the peace that has to be made. Let them eat the soup they made for us all![German proverb]'"
In which war? Many wars end when at least one side realises they aren't going to achieve their goals. Prolonging the war would only cost more.
I'm going to answer for WW1: because the war was utterly lost both on the battlefield and at home. They all knew it and they desperately wanted to keep as strong a position as possible when going into the peace negotiation.