Pitch and anatomy
Some gendered speech differences have anatomical reasons behind them. One of the changes that surges of testosterone (as in puberty) causes is that the larynx drops and grows bigger. This is why a visible larynx is sometimes called an "Adam's apple", because of its relationship to the testosterone-triggered processes of puberty.
Pitch beyond anatomy
Anatomy isn't the only contributor to gendered pitch patterns, though. Speakers are able to control their pitch within their physically possible range. This is especially noticeable in little kids, who learn that lower and higher pitched voices are part of being a boy or a girl and they join in by shifting within their range. As a result, little boys use lower pitch than little girls the same age, even though their larynxes are the same size.
Adults do the same thing, changing their pitch for many purposes, like asking a question vs. a statement, making their speech sound more dynamic and interesting, or changing how masculine or feminine they sound. Here's how you changed your pitch when you tried to sound as masculine and as feminine as possible: