As soon as sweet potatoes start to heat up during cooking, a special enzyme particular to sweet potatoes goes to work. This enzyme breaks down the tasteless, chalky starch into maltose - in other words, the starch becomes sugar. Maltose is only about a third as sweet as table sugar, but that's plenty sweet for us!
You can actually control how sweet your potatoes become by how you go about cooking them. Harold McGee in On Food and Cooking explains that the enzyme becomes active at around 135° and stops at around 170°.
This means that if you bake your sweet potatoes low and slow, the enzyme will have more time to break down more starch and the finished potatoes will be very sweet. If you cook the potatoes faster (by steaming them, roasting smaller pieces, or any other quick-cooking method), your potatoes will be less intensely sugary in the end.
Do you like sweet potatoes? How do you like to cook them?
Related: Why Is This Sweet Potato Not Orange?