Why do babies do this?

Baby slams his legs on the mattress during sleep , diaper change and play time 😫