While the specific mechanisms vary from windup toy to windup toy, all of these types of playthings work on the same fundamental energy principle: potential energy. When you wind up the toy, the energy from winding is transferred into a storage mechanism, such as an elastic band.
A good way to see this kind of action at work is to hold a rubber band between the thumbs and forefingers of both hands, twist it up tightly, then let it go. The rubber band will spin until it returns to its original, unwound shape. The tighter you twist it, the faster it will spin initially, because when you twist it tightly, you encounter more resistance and have to use more strength, putting more potential energy into the tightened rubber band.
While some toys are actually powered with rubber bands, others use springs that operate on a similar principle. With springs, potential energy is stored in the metal coils as they are compressed.
Whichever mechanism is used, a mechanical toy works by employing mechanisms that harness this power and transfer it into the moving parts of the toy in a specific way. This is often done using gears, since gears can be threaded together and used to change the direction of motion an energy output is creating. This makes it possible for, say, a spring uncoiling in an up-down direction to power a mechanism that operates in a side-to-side motion.
Gears can be placed in such a way that the device cannot expand or unwind itself without powering the toy in a certain way. A simple example of this is a jack-in-the-box. This toy is based on a wound-up spring, but when the spring is freed to decompress, it pushes up an attached doll body.
Whether a toy winds up with a key, a crank or some other mechanism, the process of winding the toy initiates another mechanical process, where gears attached to the key connect to mechanisms that either pull a device such as a rubber band or compress a device such as a spring.
While some windup toys, such as pullback cars or jack-in-the-boxes, release all the stored energy in one fast burst, other toys use gears and mechanisms that release energy in a more controlled manner, allowing the toy to run for a longer time and make more subtle motions. Gears and other mechanisms are made to provide resistance to the motion of the device through friction, by requiring more force to turn and move.