That phrase was simply about Spock sacrificing himself so that the ship might survive as he exposed himself to radiation. While it can be twisted to socialism and marxist origin, in the proper context it was simply a few words of comfort to a distraught Kirk as he had saved the ship and was dying. The parting final words of Spock dying as one who allowed many others to not perish in a disaster.
While that is exactly the impression they intended to make in the filming of that scene, I have little doubt that they were also inserting a little bit of under-the-radar socialist theory into their entertainment. The Russian Communists were also very big about promoting the struggles and sacrifices of their heroes.
I seem to recall that someone wrote an article saying that the writers did indeed intend that line as a subtle variation on "From each according to his ability, to each according to his need."
"The needs of the many outweigh the needs of the few or one."
Would you believe Nazi Germany?
Gemeinnutz geht vor Eigennutz "The common good before the private good"; Rudolf Jung popularized it in his book Der Nationale Sozialismus, 1922, 2nd edition. This became Hitler's basic stance on the subordination of the economy to the national interest. (6)
Yeah, I thought it sounded a bit like socialism.