I do not think X thought like Castro, having read his autobiography. He wanted dignity and self sufficiency for blacks, not a mommy state.
I saw an interview of Malcolm X. I found myself nodding in agreement with most everything he said.
I think he posed with Castro basically just to flip the US the bird.