Other than a cryptic hint as to the Valeyard's origins as the Doctor's future self (or part of his self), we do not know the origins of the Valeyard.
The Valeyard served as the prosecutor during the trial of the Doctor. He presented extracts from the Matrix depicting past events in the Doctor's life as evidence of the Doctor violating the non-interference policy of the Time Lords. Later in the trial he added a charge of genocide against the Vervoids.
The Valeyard had secretly tampered with the Matrix extracts to show the Doctor in the worst possible light and steer the trial to a guilty verdict. The Valeyard was acting on behalf of the High Council to cover up the Ravolox affair. As payment, the Valeyard was to have received the Doctor's remaining regenerations. It was The Master who stepped in and revealed the Valeyard's true origins.
The Valeyard escaped into the Matrix via the Seventh Door, which he opens using a copy of the Key of Rassilon. He is pursued and finally defeated by the Doctor when an explosion the Valeyard had intended to destroy the court is fed back into the Matrix due to the Doctor's tampering.
However, as Inquisitor Darkel dismissed the trial and the Doctor and his companion departed, the Valeyard was also present, disguised as the Keeper of the Matrix.