No government lasts forever, and in Germany the coalition led by Chancellor Helmut Schmidt has had a very long run. The returns from a local election in Hamburg last weekend add to the evidence that the Schmidt government is steadily losing momentum and this long cycle in German politics is coming to an end. Mr. Schmidt's Social Democrats landed in a dead heat with the opposition, a staggering comedown in a city that had once been a great center of their strength.

Part of the explanation is sheer physical weariness. The Social Democrats have been in power continuously for 13 years, and Mr. Schmidt has been chancellor for eight. The atmosphere in Bonn is reminiscent of Washington toward the end of a president's second term: all the questions are settled and all the challenges are rebuffed as naive and ill-informed. But there is another element in German election politics, and it has to do with voters' ages.

The dividing line seems to be somewhere around the age of 40. No one younger than that can have much recollection of the end of World War II and the years of fear and hunger that followed it. There are a lot of people in Germany who fled west from the Soviet zone, and there are a lot more who remember the days when no one knew whether the United States and its allies would, or could, defend their border.

Both of Germany's major parties are run by people who recall that time clearly, and whose views regarding Americans and Russians are very similar to those held by people in power in Britain, France and Italy. But well over half of the population was born since then, and some see the world quite differently. While they are a minority, they are no longer a negligible minority. In Hamburg, nearly 8 percent of the votes went to a protest movement devoted to environmental protection and radical social reform. Within the chancellor's own party, the left wing has been harassing him increasingly vigorously.

If you were to peel through the layers of obfuscating prose, you would probably conclude that much of this rebellion springs from attitudes toward the United States and a feeling that the terms of the alliance leave Germans with too little command of their own interests. That feeling deserves careful consideration not only by German politicians but by Americans as well. It's not a bad moment for Mr. Reagan to visit Bonn.