This happened to my hamster and it sadly was put down today I suggest you take it to the vet as if this is the case it will be in pain mine had a brain tumor growing inside its body .I hope your hammy survives
We've had lots of hamsters and this can be a common trait as they age into the final stages of their lives. We tend to move them into single story cages so they're at less risk of hurting themselves and monitor them carefully. As soon as we feel they start deteriorating and having a poor quality of life, we have them put down.
When a hamster has a problem walking, this could signal an inner ear problem causing lack of balance, has a tumour, or other problem. Contact your veterinarian immediately as your hamster might need to to be put to sleep.
Your hamster might be sick or maybe your hamster has a broken leg and it hurts to walk on it. I would take it to a vet.