From the beginning of the American Civil War, Virginia had two governments. The original pro-succession government with it's capital in Richmond, and a newly formed Restored or Reorganized Government of Virginia which also claimed Richmond as its capital, but really was in Wheeling (then still part of Virginia) and later Alexandria once West Virginia came into being.
The Restored Government considered the secession in violation of the Virginia constitution since it was done without the consent of the people, it was done by the legislature, and declared the existing government illegal. The Federal government, unsurprisingly, recognized them as the legitimate government of Virginia and seated its congressmen.
It was this Restored Government that signed the 13th Amendment.
For reference, here's some interesting letters passed back and forth between the Restored Government and the Federal Government.