My ankles only swell when I don't get enough sleep. Why does this happen?

Stress? Although it could be from many things, lack of sleep can lead to increased stress levels and possibly lead to increased swelling to the lower extremities. Try finding ways to calmly sleep, like meditation, decrease caffeine intake, restrict activities at night, etc.