Boys played the female roles in Shakespeare's plays when the plays were first produced because women did not perform in the theater during that era. Acting was not considered a reputable profession, and women typically stayed away from this type of work.
Therefore, female character roles were commonly played by boys between the ages of 13 and 19, while their voices were still high enough and their physiques were not fully developed. It is believed that because of diet and lifestyle, the voices of these boys broke a bit later than they do for boys in modern times, so these boy actors were able to play female roles convincingly until well into their teens. Women did not begin performing regularly in the theater in England until the 1660s.
Boy actors were apprenticed to masters, similar to how the process worked in many other guilds of the time. These boys did not always work under the best conditions. They were often burdened under heavy costumes and forced to wear makeup that contained lead, sometimes leading to lead poisoning. Some scholars have questioned whether Shakespeare's most-complex female roles could have been played by teenagers, but most evidence suggests that these parts were almost always played by teenage boys.