This is pretty cut and dried! A stallion is an intact male horse who can reproduce. That means any colt that is born is a stallion.
A stud is a male intact horse who is used in a “stud” for breeding mares.
A ‘stud farm’ uses a ‘stud horse’ for breeding the mares, hence the name, a ‘stud horse’. I’m pretty sure it was condensed down to plain ol’ ‘stud’ for conversation purposes.
So, the upshot is a stud is a stallion but a stallion isn’t necessarily a stud. Follow that??