The 15th Amendment gave African American men the right to vote even people who have been slaves. After the Civil War, the Union won and slavery was abolished by the thirteenth amendment and all races were considered equal, this way, the government was prohibited from denying a citizen the right to vote based on race, color or previous condition of servitude.
After The Union had defeated The Confederacy, the right to vote was guaranteed to all races. This was possible because the Union was in favor of equality.