When you lie down and the lower body (legs and other things) seeks level with the kidneys,it is then that the kidneys remove the water because it is easier.
Drinking water at a certain time maximizes its effectiveness on the body:
2 glasses of water after waking up - helps activate internal organs
1 glass of water 30 minutes before a meal - helps digestion
1 glass of water before taking a bath - helps lower blood pressure
1 glass of water before going to bed - avoids stroke or heart attack
Water at bed time will also help prevent night time leg cramps.
Your leg muscles are seeking hydration when they cramp and wake you up with a Charlie Horse.