Remark
It is easier to explain why they almost won. After that deal with why they didn't.
Why the South Nearly Won
One: They had a superior military leadership, especially at the beginning of the civil war. Robert E Lee had a great military mind and used his superiorly trained troupes to best advantage that is until Gettysburg.
Two: They had a very mobile cavalry under the superb leadership of J.E.B Stuart. This is not the same answer as one. The south had a terrific advantage in the use of her cavalry, again until Gettysburg.
Three: In the beginning, the armies of the south had better reasons for fighting than did the north, or at least they thought so. Fighting for freedom is always a great rallying cry.
And why the North Eventually Won
However Gettysburg was the turning point of the war. Lee made a mistake which he was analytical enough to acknowledge. He was overconfident in what his troupes could do especially at the beginning of Gettysburg.
What losses Lee encountered could not be easily made up by calling on civilian help.
The north developed a brute force tactic in conquering the south. Grant and Sherman simply swept across (mostly) Georgia. Lee by this time was not able to meet the challenge. Grant's method was cruel but very effective.
Gone With the Wind (the book and movie) made a remarkable statement delivered by the character Rhett Butler when he said "The South will lose because it does not make one canon." What he meant was the South did not have the same industrial might that the north had.