Due to religious reasons and the fact that gambling induces addiction.
Stock market IS a huge casino, but also the life itself. Picking the right major for college, buying real estates, starting a business, deciding to live in a bad neighbourhood for a cheaper rent, or even deciding to smoke the first cigarette are all decisions with risks and different outcomes. If gambling is defined as putting money (or objects with monetary values) with some probability of getting a higher monetary value as outcome, then almost anything is gambling.
The difference what you probably think of, is whether the "gambler" acts responsibly (so to show the gambler does not act "addicted"). There are many stock-market-products, which are "borderline-casino", e.g. football player derivatives (there is also an argument to be made, whether this is just an overly-complicated slavery). Depending on where the stock exchange is, there are different regulations, which prohibit such products. Casino is not a stock exchange because there is some regulations, of which a stock exchange has to comply to (in order to be called "stock exchange" legally).
When as an investor you don't know anything about stock market it is gambling, but when we learn about the market apply our knowledge (do technical and fundamental analysis) then it is investing and trading not gambling.
Gambling is betting on something out of speculation based on sheer luck and there is no basis to bet on something uncertain, where you your self don't have the knowledge, minimum research and competence to do it
Gambling has been frowned upon since the Middle-Ages as it always hurts the poor. The desperate poor will invest a higher percentage of their income on lotteries as there is no other path available to them to get out of poverty.
Most churches from on gambling as the harm it can do outweighs the small pleasures it provides.