In Shakespeare’s youth the mooncalf was a figment of the imagination, a monster of some horrendous sort conjured up by moonlight in the eye of a frightened person too scared to see straight.
But by the time Shakespeare wrote The Tempest (1613), he or others took it to be an actual being, a congenital monstrosity such as a malformed calf.
The term was then applied to a person who was a congenital idiot or, as though moonstruck, acted as if deranged.