Rectal prolapse occurs when either the rectal mucosa or the entire wall of the rectum protrudes through the anus.