Germany (as many other countries) finds itself in a position where it cannot avoid to depend on others and has to chose how it distributes dependencies.
It was difficult for Germany to handle the situation where they had to replace their dependency on Russian energy resources. But we tend to overlook that Germany actually could replace it. And still, Germany does not buy gas from the US, not only because it's more expensive but also because if the US would chose to capitalize on that dependency, Germany would risk to trigger other dependencies to the US in an escalation spiral.
Germany tries hard to balance its dependencies such that it does not depend more on one single entity that is absolutely necessary. It has to act like this, because it cannot trust any such entity that they would not use these dependencies to blackmail Germany. And this is not a conspiracy theory, there are plenty of examples where political or economical capital has been invested in order to unduly influence governments.
Whether Germany's stance towards China/Huawei/5G in particular is wise is a different question, but everybody makes mistakes.
The strategy to include China in the western global economy was not a singularly German strategy, but Germany fully supported it. Because of its economic layout, Germany really didn't have much choice. Now that there is a new hopefully cold war between the west and China looming over us, this is especially problematic for Germany. In such a war, Germany would not be so much an actor as it would serve as a battlefield (economically). That's why Germany does everything it can to avoid fueling the conflict. If that means letting the Chinese intelligence roam in their underpants, where US, Russian, UK and all other intelligence agencies are at home already, that's not really an issue.