Sometimes happens to me after a long (60+ m) or hard ride. I don't know if it's just the placebo effect or not, but drinking a large bottle of GatorAide seems to really help (along with some stretching). I think it's salt/electrolyte loss in my case.
I've also heard of people's saddle height affecting this, although the mechanism is unclear to me.