It is said that Bitcoin can be subject to being stolen if I have it in my wallet on the smartphone, and is more secure in the Ledger.
That is wrong. They are both "in the Ledger".
Although we speak of having money in a wallet, in reality the money is all kept track of in the blockchain (which is more like a transaction journal than an accounting ledger). The only important information in a wallet is a secret number known as the master private key.
So the money is in the same place regardless of whether you use a wallet to control your money yourself or whether you give all your money to some business in return for an IOU that just gives the illusion of owning money.
If the business has the secret key on their computer - you have to hope their computer isn't hacked, is well-managed and that the business doesn't have a dishonest owner, dishonest employees or dishonest office cleaners.
If you have the secret number on your computer, you have to take care that your computer isn't hacked, you have to make backups and look after them.
is more secure in [a hardware wallet]
Yes, a hardware wallet such as the Trezor Model T or Ledger Nano are among the safest places to store a private-key. You still need to make a secure copy of the recovery-phrase in a separate and safe place. You still need to practice recovery.
if I buy it using Coinbase, Robinhood, or Gemini, ... and suppose the account itself is not hacked, does that mean it is quite safe against theft?
History demonstrates that exchanges are not quite safe against theft
Although it depends what "quite safe" means to you.
See the story about Quadriga-CX. I'd say look at MtGox and all the others but for many of these we can't tell if they were hacked or if the owners colluded in the theft. Prior to failure, many of these were either the most trusted exchange in existence or among the most trusted.
You also open up another attack vector - access to your login credentials entered via your computer or phone (or cybercafe WiFi).
You might think big exchanges employ a lot of security experts, however their information systems complexity and security problems are much larger in scope than yours are when running a single-person's wallet on one device.
General advice is not to keep any money on exchanges that you are not currently actively trading.