German disunity was tied into autocracy and backwardness of many smaller German principalities, and the drive for unity was tied into the drive for democracy. Unity was also tied to a power grab by the largest country to end up in the Reich, but the OP asked why smaller ones wanted unification.
- Two possible answers to the German question were the Kleindeutsche Lösung (lesser German solution) and the Großdeutsche Lösung (greater German solution). The Großdeutsche Lösung did not happen and many German-speaking countries and territories are now no part of Germany.
- Disunity caused tax barriers and obstacles to economic development. The Zollverein was no satisfactory solution.
- The Napoleonic Wars had been a clear sign that the individual kingdoms, duchies, cities, etc. could not hope to prevail in geopolitics. Germany calls the campaign of 1813 the Freiheitskriege (liberation wars).
- The March Revolution was about pan-Germanism and about democratic rights.
So there is no single answer, and the outcome was not inevitable. One could tell counterfactual stories about a different outcome.