This is a quote that has to do with the nature of relationships and what makes a person or a country likely to ally itself with another. It is saying that people or countries can become allies even if they really do not like each other all that much. As long as they have an enemy in common, they can be allies.
A perfect example of this comes from World War II. In that war, the US and Great Britain (on the one hand) were allied with the Soviet Union. Neither country was friendly with the USSR before the war and they would be enemies again soon afterwards. But during WWII, they were both enemies of Nazi Germany. Because the Soviets were the enemy of Hitler (an enemy of Britain and the US), they were considered friends of the US and Britain.
The phrase the enemy of my enemy is my friend is a proverb that advances the concept that because two parties have a common enemy, they can work with each other to advance their common goals. Often described as an Arabic proverb, there is also an identical Chinese proverb.
In foreign policy, it's a doctrine commonly used to interact with a significant enemy through an intermediary rather than through direct confrontation.
Examples throughout history are common, such as longtime enemies Britain and France uniting against Germany during World War I, the Western capitalist democracies aiding the Soviet Union following the Nazi invasion during World War II, or U.S. support for anti-Communist dictatorships during the Cold War.