Mix of price, compatibility, dev support. Atari was behaving like a consumer electronics company and left the developers starved for information on the computer, while Commodore shipped every unit with a very comprehensive manual. The C64 was a clean break from predecessors in most respects and the VIC II was more straightfoward to program for typical raster graphics(even if it missed some of the neat features of Antic and CTIA/GTIA), while the Atari had a legacy install base with lower memory capacity. So, by the mid 80's the Commodore had become the defacto cheap game machine, in absence of new console competition. It was never a great applications computer, in fact(I/O limits derived from the low cost architecture meant it did less than an Apple II for many development and business tasks) but it hit a certain sweet spot of being a great first computer.
Atari after the Warner acquisition was a hugely dysfunctional company - there are a lot of proposed alternate histories where different projects got prioritized and execution was better, that would have given them a stronger position in the computer market. As it is, they still put out some pretty cool hardware.