It seems this question has been asked many times on the Internet, for instance here it is on Reddit, and here it is on some Tolkien forum. In both cases, the answer can be summarized in a few points:
They're going through the mountains, off the beaten path. They're not going to get much use out of horses in such terrain, and even if they'd avoided Moria they probably still would have reached a point at which they'd have to leave the horses behind.
I would have traveled lighter and brought no animal, least of all this one that Sam is fond of, if I had had my way. I feared all along that we should be obliged to take this road.
They want to be stealthy. Horses are harder to hide, and harder to keep quiet when evil is afoot.
The country was much rougher and more barren than in the green vale of the Great River in Wilderland on the other side of the range, and their going would be slow; but they hoped in this way to escape the notice of unfriendly eyes.
Half of them are half-sized. Hobbits and dwarves aren't big enough to properly handle horses.
It's wintertime. They'd have to carry extra food, water, and bedding for the horses, which would quickly become more trouble than it's worth.
So for these reasons, they don't ride horses out of Rivendell. When leaving Lothlorien, they leave in boats, so they can't take horses with them. After that, when horses are available, they are used.
Plus, I think it's worth mentioning they brought a pony who carried some of their gear, at least until Moria, where (according to the book) he bolted and made his way back to Bree.