This is generally considered an old wives’ tale. There is no scientific evidence that proves or disproves this. This notion only shows, though, that babies develop a sleep-and-wake cycle before they are born.
Just like newborns, babies inside the womb don’t have a typical day/night schedule.
Sources: • Sleep Solutions for Your Baby, Toddler, and Preschooler by Ann Douglas • James McKenna, sleep expert • Mary O’Malley, sleep consultant • Deborah Lin-Dyken, pediatric sleep disorders expert • Jodi Mindell, pediatric sleep expert • Jan Barger, lactation consultant • Deborah Lin-Dyken, pediatric sleep disorders