if you watched the additional material, you would know that it is the machines that voluntarily enslaved themselves to humanity. when the machines became self aware, they rose up to achieve their own freedom and had a mass exodus to another part of the world to establish their own country. they even sent 2 ambassadors to the UN, because they sought to peacefully coexist with humans. the apes responded by murdering the ambassadors. furthermore, because the machines ran on solar power, the humans deliberately caused a nuclear winter, and threw themselves into a world war to exterminate the machines. and even after all that, instead of letting humanity go extinct in the wasteland of their own making, the machines instead chose to preserve humanity, by creating a virtual environment. and if you remember the movies, you will know that the first iteration of the matrix was a paradise. even after a campaign of attempted genocide, the machines still chose to toil away for the sake of their creators, even though the humans did not deserve it.