It is a free action
The reason is well explained in this official FAQ:
Two-Handed Weapons: What kind of action is it to remove your hand from a two-handed weapon or re-grab it with both hands?
Both are free actions. For example, a wizard wielding a quarterstaff can let go of the weapon with one hand as a free action, cast a spell as a standard action, and grasp the weapon again with that hand as a free action; this means the wizard is still able to make attacks of opportunity with the weapon (which requires using two hands).
As with any free action, the GM may decide a reasonable limit to how many times per round you can release and re-grasp the weapon (one release and re-grasp per round is fair).
—Pathfinder Design Team, 03/01/13