This sounds like sleep paralysis:
"Sleep paralysis is a feeling of being conscious but unable to move. It occurs when a person passes between stages of wakefulness and sleep. During these transitions, you may be unable to move or speak for a few seconds up to a few minutes. "
"Up to as many as four out of every 10 people may have sleep paralysis. This common condition is often first noticed in the teen years. But men and women of any age can have it."
https://www.webmd.com/sleep-disorder...ep-paralysis#1
You should mention it to your doctor. There are a number of causes, which the WebMD article lists.