Usually newborns through about four months of age will have a tendency to cry in their sleep. As they grow, this becomes less and less. Why baby cries in sleep is never a set answer because each baby is different.
Learning to Sleep
Newborns are learning sleep patterns and their bodies are adjusting to being outside the womb. This unfamiliar environment coupled with their bodies twitching and learning to sleep sometimes lends to the baby crying while sleeping.
Starting to Wake
Babies that are not quite awake yet, but are trying to wake up will cry out. Babies will twitch and move while sleeping and if they are not in a deep sleep this could cause them to cry. The baby may also be laying in an awkward position and causing some pain, therefore inducing crying while sleeping.
Babies, just like everyone else, can have nightmares that cause them distress and fear. A particularly stressful day could cause a baby to have nightmares as they sense the stress around them throughout the day.
Hungry or Soiled
Babies that are in a deep sleep may cry because their subconscious is telling them they are hungry. As babies sleep, they cannot hold their bladder or bowels and will therefore make a mess in their diapers. Once they soil their diaper, then they will be uncomfortable and will cry out. If the crying increases or becomes frantic, then it is best to wake the baby to find out if they are hungry or soiled.
Each baby is unique and each cry means a different thing. It is up to the caregiver to try to guess what the baby needs or why they are crying out in their sleep.