The simplest mechanism for a species to alternate forms between generations is to have a diploid/haploid lifecycle. As per sumelic's comment, see https://en.wikipedia.org/wiki/Alternation_of_generations.
To explain what that is, we humans have two full - but slightly different - copies of our genome in most of our cells (diploid). However, when we reproduce, our eggs & sperm have only one copy (haploid). When an egg and sperm joins to form a zygote, the zygote is again diploid.
Your hypothetical species could have a diploid form that produces haploid offspring - rather than producing single-celled gametes, it simply produces an entire multi-cellular being that in a biological sense is a macroscopic gamete (not necessarily called a gametophyte as in the Wikipedia article, as phyte implies a plant), which can then get together with another macroscopic gamete to produce a diploid offspring by more traditional sexual reproduction. The macroscopic gamete form may be hermaphrodite, or may have sexually-dimorphic male/female forms.
You may have all diploid organisms producing macroscopic gametes, or only one gender of diploid organisms may produce macroscopic gametes, which then go to fertilise - or be fertilised by - the opposite-gendered diploid form, which still uses single-celled gametes
Such a system may evolve when the diploid form for some reason has difficulties getting close enough to others of its species to reproduce by the more traditional means of single-celled gametes and close-external or internal fertilisation.
As the distances between diploid individuals increases, the necessity arises for the gametes to be increasingly more robust and capable of travelling over longer distances; this leads to multicellularism, and as the multicellular haploid gametes evolve in parallel, they develop their own distinct biology, quite different from the diploid parents.
As for metamorphosis, this is a very common strategy. Metamorphosing species have an advantage in that juveniles and adults can have different habitats and/or food requirements, thus reducing intra-species competition. It is not beyond the bounds of possibility for there to be different juvenile, adolescent and adult forms.
The possibility also exists for juvenile/adult/post-adult morphs in a species which cares for its offspring; the juvenile is just that, the adult lays the eggs or gives birth to the offspring, and the post-adult cares for the eggs/offspring and perhaps also the adult morph, but is no longer capable of reproduction itself. This could be seen as a parallel to the human child/parent/grandparent system, in that grandparents are no longer capable of reproducing, but still provide invaluable assistance to parents in child-rearing and education.
So, in the example in your question, there will probably have been a period in your species' distant evolutionary history when it had only one form or set of morphs, which was sessile or slow-moving in its reproductive morph, and did not exhibit clumping. Difficulties in obtaining sufficient proximity for sexual reproduction led to the evolution of more and more mobile gametes, which eventually became multicellular and quite different from their parents, complete with their own growth patterns and metamorphoses.
Once we have the alternation of generations in place, there is no longer a requirement for a sessile reproductive form to remain sessile, and evolutionary pressures may have led to the reproductive form remaining motile, while still retaining the alternation of generations.
A's would mate with B's if in the evolutionary history, only the male gametes were motile and the female gametes remained with the mother. B's would mate with B's (either hermaphroditic B's or male/female B's) if in the species evolutionary history, both male and female gametes were released into the environment.
You may have an even more extreme example of this if one of the variants reproduces parthenogenetically into a third form before it then produces one of the other forms.