This is part of a general admonition against chukkat hagoy, the ways of the heathens.
The problem was both theology and ethics. In fact the two issues were intertwined. Because they had a false theology they had false ethics, and Israel had nothing to learn from them.
It is not just an ancient historical question, because many of the cultures whom we encountered, even in modern times, were also dangerous.
Not only Jews suffered from such regimes and ideologies; their own people were often victimised. Experience proved that when Jews were not safe, nobody was safe.
Sometimes Jews thought it was a counsel of prudence to make their peace with their neighbours, but it rarely worked.
In Germany there were Jewish thinkers who adulated German civilisation, but it turned against them and unleashed a Holocaust that destroyed the dream of harmonious symbiosis.
What should a Jew do then when it is obvious that a nation failed to meet the standards that were second nature to Judaism?
The answer is twofold – increased dedication to Judaism and its ideals, and unremitting determination to improve the ways of the host society.
Leo Baeck said that the Jew is the eternal protestant who never accepts the present situation as the best of all worlds.
One can and must be a loyal citizen of the country where one lives, but that must never be at the cost of surrendering or squashing the Jewish moral conscience with which one was born.