In the case of Lucky Star, this is because the drama CD predates the anime by about two years, and was produced by a completely different group of people. When Kyoto Animation took on the Lucky Star anime project, they decided to cast new voice actors. Why? I don't know in this specific case, but one possibly contributing factor is that drama CDs are likely to have a smaller budget than anime, meaning that there are probably more constraints on which voice actors can be hired. Then again, maybe the producers just didn't like Hirohashi Ryou as Konata, or maybe Hirohashi had scheduling issues (because, after all, the Lucky Star anime wouldn't have been part of her contract to do the drama CDs). Who knows?
This is a pattern you will see from time to time - there are some manga/LN franchises that get drama CDs before getting an anime adaptation. In these cases, the drama CD cast is likely to be replaced when it comes time to make an anime, simply because the production staff for the drama CDs and anime are different, and so there's nothing really necessitating that the anime production staff use the drama CD cast. Kara no Kyoukai is another example of this - there was a drama CD back in 2002, but the entire cast (besides glorious Nakata Jouji as Araya) was replaced for the movies.
On the other hand, when the drama CDs are a tie-in to the anime, you'll almost invariably see the same cast used for both, since they're both being produced by the same people/companies. I know of no exceptions to this, though I wouldn't be too surprised if there were some exceptions out there.