There's a number of reasons, from features not present (decocker/safety) to location of manufacture (the US government prefers its weapons to be produced on our own shores; Glock until recently has only made them in Austria), to other things too.
Moreover, the G17 was developed in 1982; the Beretta M9 was selected in trials in 1985; while the G17 could have taken part in that trial (it was in existence), it wasn't part of them.
The Glock design makes for a good gun, but it's hardly the only good pistol out there. Short of a huge advantage (which, in truth, it doesn't have), there's little point in switching everything over from the M9 on a large scale. It's not good enough for a potential replacement to be marginally better, it has to be good enough to justify millions (if not billions) of dollars spent to buy the guns, train the troops, get all the spare parts and magazines, and so on. I just don't know that anything out there is good enough to justify a change of that scale.