A hamster will 'freeze' temporarily due to fear or surprise. Their eyesight is poor, so they need to listen and sniff to work out what's going on. You can alter your hamster’s environment to make it less stressful. Making sure there are no other pets on the prowl, and keeping sudden noises to a minimum, is a good start.
This 'freezing' behavior is not usually due to a health condition. However, if your hamster does it all the time you might want to get him checked by a vet.

Sometimes hamsters freeze, listening out for danger - the hazard in this photo is obvious enough!
The usual cause of hamsters stopping still is fear. If the pet is new, this is bound to happen in the early days. It will be a strange environment for the pet, and there will lots of new things to get used to. Hamsters are made nervous by threatening noises. This could be something not immediately obvious to you, such as a noise on the TV, cell phone or radio. Like all the rodents, hamsters have very good hearing. Have you watched squirrels 'freeze' in the local park? It's the same thing going on there.
By stopping moving, a hamster can focus its senses on the threatening/unusual sound or smell. In the wild, freezing when they hear a noise allows them to judge whether there's any danger around, reducing their chances of being spotted by a predator.
Skyla, 29 March 2020
This recently happened to my hamster. I was having a tough time and picked her up. Then suddenly, she froze. I poked her while I was still in tears. She just pointed her ears to me. I guess she was listening to my sobbing. This used to happen to my former hamster, too. She would also point her ears to me whenever I was sobbing. Then, they would both let me pet and cuddle them. It was very soothing for me.