To make a long story short: they don't necessarily know how many plaintiffs there are or how much they were injured when the suit was initially filed. That is discovered over the course of the litigation, so by the end they divide up Y dollars amongst X plaintiffs, and it ends up being $3.00 or $300 or $30,000 apiece. Anybody who has a claim which they know to be more than paltry is welcome to opt out of a class action and file their own independent lawsuit.
In addition, even if a large company harms a million people for $5 apiece, they have still committed legally recognizable harm to the amount of $5,000,000. If lawyers bring a class action lawsuit, do all the work, put up (almost) all the fees and expenses, and collect a reasonable fee of 25%, they end up with $1,250,000.
That sounds like a pile of money, but, on the other hand, it's a fee of $1.25 apiece for a million clients, each of whom they managed to recover funds for. The company lost what it stole in the first place; the customers managed to get a refund (which they would not have been otherwise able to get) minus a reasonable attorney's fee; the attorneys were compensated for the labor and risk.
Many class-action lawsuits are justified; many are ill-founded or ridiculous. Continuing reform of this powerful legal tool is an excellent idea; moving more class actions to federal court is a good start.