Smegma (the yucky build up) is a mixture of skin and bacteria from the penis and sheath, and discharge from his urethra - studs have a bit more going on than geldings. Some horses are better about letting it hang out at bathroom time which helps them stay cleaner and anatomy and skin chemistry has a lot to do with it too.
The "bean" is a build up off smegma in a pouch or pocket surrounding the urethra.
Studs get a "cleaning" when they breed and any beans tend to get dislodged.
Just like some people smell worse quicker than others from the bacteria naturally found on our skin. The chemistry of our skin plays a factor there.