Different speeds of action, different densities of medicine, shelf lives, etc. Form follows function and all that.
There are many factors that go into that decision.
First and foremost is the way to deliver the _active substance_. Can be immediate (pills are not the best for immediate delivery), delayed (most common) or extended release (e.g. the AS gets released in doses over a period of time).
Capsules IIRC can only deliver immediately but AS on capsules has faster absorption compared to pills.
Cost is another factor: AFAIK pills are usually cheaper - although I don't work at the industry so don't quote on me on this.
So it's the way you want to be delivered, characteristics of the AS, cost, etc.
source: I have a 5-year degree (EU) in Pharmaceutical Sciences.
Sometimes half a pill comes in a capsule!
If you look closely the content of a capsule is lots of tiny pills...
Capsules are more expensive and can’t be easily split by patients so pills are generally preferred by manufacturers. Reasons to use capsules: