When someone dies their body begins to go into rigor mortis which means the persons body is getting stiff.
The reason the body moves after death is due to the muscle spasms that are happening as the body stiffens up.
The body is not actually alive nor is the brain actually causing those muscle spasms because the brain is no longer active when someone dies.
It's just natural movements and spasms that occur and they can seem scary to someone not used to working with dead bodies.
When my grandpa died years ago I saw his body move slightly and it scared me because I was a kid and the police officer that was there to make a report on the death told me it was normal and nothing to be scared of.
He said it was called a Cadaveric spasm, also known as postmortem spasm, instantaneous rigor, cataleptic rigidity, or instantaneous rigidity and it is a rare form of muscular stiffening that occurs at the moment after death happens.
The muscle spasms after death can persists into the period of rigor mortis.