Now the once female is obviously a male. The eggs turn out to be viable, and the new male continues to change until he is as pretty a male checkerboard cichlid as I have ever seen. Time to do a little research. Many fish species, the vast majority of which are marine reef fishes, are hermaphroditic. A hermaphrodite is an organism that has all the parts that they need to perform the reproductive role of either the male or the female.
Many invertebrate organisms are hermaphroditic.
Snails and earth worms, for example, can copulate with any other individual that they meet. This is a real advantage. Imagine how fast a population could grow if every individual in the group can produce eggs and any other individual can fertilize them. Fish are not quite that advanced as hermaphrodites. Protogynous hermaphrodites have populations in which every individual starts out life as a female.