There can be different reasons for this happening, but one common reason is that the liver does not properly or totally break down the alcohol. This can be due to poor liver health or too much alcohol consumption. The only thing you can do, then is to avoid drinking alcoholic beverages.
Alternatively, you can also try eating bananas after a drinking session. This is because one possible reason for your aching legs is that the levels of potassium in your body dip considerably due to the alcohol. Eating bananas will help you increase those levels significantly, thus alleviating the pain that you feel.