There is backstory that the films could have gone into, though I don't know if it was written before or after the first film. The humans in the matrix were allied with the machines and they put them in the matrix to protect them from the war. They were being benevolent.
They benevolently feed the dead to the living