I wonder if this has to do with the water content of the bean. Perhaps your beans are particularly dry when first ground. Then after several hours / days, the grounds absorb water from the atmosphere. Have you ever noticed very dry powders allow water to bead up? This is because very dry material is hydrophobic (water repelling).
Some espresso makers will give the fresh grounds a tiny bit of hot water followed by a delay and then the full shot. This delay, I think, moistens the grounds. If your espresso maker has no such delay, try moistening the fresh grounds yourself before getting a shot.
Certainly the answers regarding grinder quality and grinding ahead of time have merit, but the OP obtains "good coffee" using the same, apparently mediocre, grinder when the grounds are >one day old. Grinder type does not explain this observation.