I have a bit of a spiel on the adjacent topic of the origin of colony structure and the basic caste system that I'd written previously:
Evolutionarily speaking, workers are just underdeveloped queens. In most other non-eusocial animals, every individual is a reproductive. Ants evolved from a regular solitary wasp, just females and males. There's a few theories for exactly how the transition to eusociality started, but it is all just a very modified form of that starting point of a solitary wasp.
At risk of anthropomorphizing evolution:
The female wants her reproductive offspring to be as strong as possible, and the best way to do that is to have more help raising the kids. But other wasps aren't gonna voluntarily help her raise her offspring, unless they have no choice. So the species evolves to have the females deliberately stunt their first generation of offspring, and said stunted offspring are no longer as reproductively fit. So the next best option for the stunted offspring that want to still spread their genes is to help their family members (in this case their next generation of sisters) to be extra strong and fit. This eventually got to the point that the female lived quite a while and developed a spermatheca, and the stunted forms of the females lost their wings, and there started being more and more generations in each "family", and boom, you have the basis of a primitive ant.
So in evolutionary terms, workers are deliberately underdeveloped queens, that, since they are unable to reproduce very well on their own, resort to helping their relatives, the colony. Workers in ants, and all other eusocial hymenopterans, are all females, all have ovaries (though usually quite small or vestigial compared to the queens'), though in other eusocial insects like termites the workers are male and female.
The specifics of colony reproductive structure vary a lot between species. In some cases the workers aren't as strongly reduced from their "original" queen form, and still have spermathecae and developed ovaries, and thus can still function as a queen if not actively suppressed by the dominant queen in the colony. In others, they've lost the ability to do anything but lay unfertilized male eggs. In others, the workers have developed the ability to lay diploid female eggs without mating by cloning themselves.
In a colony of a typical species, there will be one or more queens, which lay either unfertilized, haploid eggs which develop into males, or fertilized, diploid eggs that develop into females, either workers or new female reproductives. The male and female reproductives participate in mating flights after which the females drop their wings and found a new colony.
There are many species with gamergates and the exact colony structure varies greatly between species. Some species, as mentioned above, have workers with more developed ovaries and a spermatheca. These workers are capable of mating and producing fertile, diploid eggs that can develop into female reproductives and/or workers, and these fertile workers that take up egg-laying roles are referred to as gamergates. Some genera, (e.g. Diacamma, Dinoponera, Ophthalmopone, Streblognathus, some Rhytidoponera) completely lack a gyne ("queen") caste, and reproduce only through gamergates. In other ants, gamergates exist in addition to regular gynes and serve as secondary reproductives. In others, a gamergate worker will take the place of the original gyne queen when she dies. Gamergates will sometimes inbreed with males from their own nest, sometimes they will leave to outbreed and then return. In the case of Harpegnathos, they do a bit of everything. They have regular gynes that outbreed and disperse and found new colonies, and have gamergates that co-occur with the gyne queens, but also can have the gamergates take up the position of queen after the death of the gyne queen. In this way, colonies of Harpegnathos can in theory last forever, or at least until they become too inbred; I have personally seen colonies of H. saltator in the ASU ant lab that are multiple decades old.