You get one by taking part in testing a site or game before it launches — and only if the people running the test hand out badges for it.
That last part is the catch. Plenty of betas give you in-game rewards or a founder's title, but a badge specifically is a cosmetic the developers have to choose to create. Watch for open beta announcements on official channels and read what the reward actually is before signing up expecting one.