Why did the North go through several commanders while Robert E. Lee remained in command of his troops for the whole war?
There are at least two reasons for this.
First, Robert E. Lee was simply a very talented general. He was very good in terms of tactics and strategy, which meant that he was able to pick the right battles to fight and to fight well in the battles he chose. He was also inspirational to his men, giving them the sense that he cared about them and would do his best for them.
Second, the North was much less militarily inclined than the South. This meant that there were no true standout generals in the North who were the clear choice to be the leader of the Northern armies. It seemed like McClellan would be that man, but he turned out not to have Lee's strength of character or decisiveness.
What it really boils down to, then, is that the South was fortunate. It provided the bulk of the officers of the pre-secession regular Army and it had the good fortune that Lee was such a talented man.
In addition to the above response, Union military leadership was governed by a "hands on" President and the constant "looking over the shoulders" created anxiety in many Union generals. At the beginning of the war particularly, the Union army was massed in very close proximity to Washington D.C. and it was all too easy for the politicians to watch what their army was doing (or not doing in the case of being unaggressive). Though Jefferson Davis was the Commander in Chief of the Confederate forces, he gave Lee a very long leash to do what needed to be done.