These are called muscle cramps. The lack of electrolytes (essentially salts) and water circulating within your muscle tissues is what causes them. I don't remember 100% how it biologically works but I can tell you that stiff muscles + dehydration + lack of electrolytes = a recipe for muscle cramps. Just make sure you drink enough water or sports drinks while and before playing badminton. Warm-up and stretching is also extremely important.
For me, muscle fatigue, sleep deprivation (nervousness) and lack of stretching are the 3 big causes. Dehydration isn't a part of the cause for me and honestly it's impossible to prevent. Even if you drink 10 sports drinks, you will still get dehydrated if you exercise long enough. I also don't believe in the magnesium, potassium, calcium supplement arguments. The studies for these doesn't seem very convincing. Perhaps it works for some people...
It works for me. I don't used to drink any of these and partly also due to my low salt and sugar diet if with home cooked food. I can hardly recover after the match and feel tired for the next 2-3 days. before gaining physical strength for another game. I started drink isotonic drinks out of curiosity and found my recover at faster pace. Also, to ease recover, I also apply some muscle rub which helps supply more oxygen to the fatigue muscle to assist recovery.