There were both pragmatic and ideological factors. Pragmatically, the Israeli state was an ally of the USA and the capitalist West in general, and so supporting the Arab forces was a logical move for the communists. Egypt was also considered a Soviet ally around this time (praising the USSR as a "sturdy friend"), and so the other socialist states took part on the Arab side.
Ideologically, the motivation would be anti-imperialism, which is a core tenet of communist ideology. Israel's actions against the Palestinians are often seen as imperialist in nature, and so the global communist movement has historically supported Palestine. This would not be the last time that socialist states got involved in such affairs; Cuba in particular intervened in numerous anti-imperialist struggles over the years, such as Angola, where they helped to defeat the South African apartheid government, earning the praise of leaders like Nelson Mandela.
Sources