You've answered your own question here. You count "grains" of rice and "crystals" of sugar. The grains and crystals are countable. The material that they constitute ("sugar" and "rice") is not.
Stars, on the other hand, are entities in themselves. Although there are a great many of them and counting all of them individually is (as you point out) impractical, they are not clustered close together. So counting the small subset of visible stars in a specific area is achievable.
You could say that the equivalent of "grains" to "rice" is "stars" to "universe". We count the stars, not the universes. We count the grains, not the rice. (And yes, you could add words like "galaxy" or "nebula" in there, too, but again, these are entities in their own right.)