Cannabis wasn’t always the beautiful frosty well-structured buds that we know today. Cannabis used to always have seeds, it produced small sporadic buds and didn’t have near the THC content cannabis has today. The major catalyst in that change was the discovery of growing female plants by themselves with no male plants present. When the buds (flowers) of the female plant go unpollenated they don’t produce seeds (sensimilla) and put that energy towards increasing in size and producing more trichomes, to trap more pollen. The final product was larger, more attractive flowers with a significantly higher THC percentage. But that’s not to say that you’ll never find a seed in modern cannabis.
Cannabis can go hermaphroditic, meaning the plant will self-pollinate. They will generally only do this in specific situations, one of which is if there is significant stress put on the plant during the flowering cycle. Cannabis plants use environmental sensors to determine if it will survive long enough to be pollinated. In that case, it will produce male flowers as well as female flowers to pollinate itself. The other reason is the genetics of the plant. Certain genomes are more susceptible to going hermaphroditic. For example, Thai landrace strains are much more likely to go hermaphroditic compared to Afghani strains. Most of the hermaphroditic genetics nowadays have been sifted out of the population, as it is considered not a desirable trait for cannabis.