Your muscles are getting tired an affected by lactic acid, which is generated by muscular action. The best way to avoid those are by doing some warming before riding, have plenty of water/electrolytes while cycling, drink some base solution after exercising (the best one is plain club soda, the base will fight the acid), and do some stretching when you finish your ride. Use these tips and let me know if they work as well as they do for me.