The string on a yoyo is attached to the center of the yoyo called the axis. When you release the yoyo it goes down the string and builds up kinetic energy.
When the spool gets to the end of the string it keeps on spinning. When you tug up on the string the axis rubs against the string and allows the spool to travel back up the string.
These principals are know as the science of motion in physics.