Cognitive Science: An Introduction/Acting to Learn
When children play with toys, they are trying to practice dealing with the world, and learning how it works.
In one test of this idea, psychologist Aimee Stahl ran an experiment in which infants were shown objects behaving in various ways. One object was shown to defy gravity (it was staged, of course.) When given an opportunity to play with the toy afterward, the infants were more likely to drop it on the ground. Some infants saw toys that appeared to pass walls, and later, when they played with the toy, they would bang it on the table. What we think is happening here is that the infants already had some knowledge that solid objects obey the law of gravity and are unable to pass through walls. So when the kids observed otherwise, they tested this knowledge, and the fact that they used different tests for different objects supports this view. 
- Stahl, A. E. & Feigenson, L. (2015). Observing the unexpected enhances infants' learning and exploration. Science, 348, 91-94.