To answer this question, you have to consider the history behind the office of the President. During the Constitutional Convention, the issue of term limits for the Presidency was debated quite extensively. Ultimately, however, the Convention decided not to institute term limits on the office, as the decision regarding the number of terms to elect a person to the Presidency was deemed to fall within the hands of the electoral body.
As the first President, George Washington served two terms, and declined to seek a third. He noted at the time that his decision was not based on an intention to set a precedent, but rather on his age and desire to no longer be President. After Washington, John Adams served one term, and then Thomas Jefferson was elected for two terms. Jefferson also declined to seek a third term, and commented that even if terms limits were not ordered, there must essentially be custom and practice limited one's service in the office of the Presidency, otherwise the practical intent would be to make one person the President for life. With Washington and Jefferson, and with each successive person who declined to seek a third term, the precedent was set for custom and practice to be only two terms.
That's not to say that no one every sought a third term. Grant comes to mind, but he was defeated in seeking his party's nomination by Garfield, who was subsequently elected President. Teddy Roosevelt served two terms, and then declined to seek a third in favor of his handpicked protégé, William Howard Taft. When Roosevelt became fed up with how Taft served during his first (and ultimately only) term, Roosevelt founded his own party (the Bull Moose Party) and sought the nomination for a third term. He and Taft (still the Republican nominee for a second term) split the vote, and Woodrow Wilson was elected to the Presidency as the Democratic nominee.
It wasn't until Franklin Roosevelt became President that the issue reached a head. Due to his efforts to alleviate the pains of the Great Depression, and his later leadership during World War II, FDR garnered great support throughout the country, and was ultimately elected to FOUR terms as President. He died in office during his fourth term, and was succeeded by Harry Truman, but had FDR finished his term, he would have served 16 years as President, assuming he did not get a fifth term.
Although FDR and his programs were very popular with the people, the length of his service was not popular with other politicians, who both sought higher office for themselves, and who were concerned with the increasing power of the "Imperial Presidency," i.e. the idea that a President can accumulate so much power that he ends up taking the power away from the other branches of government. If left unchecked, an Imperial President could, as Jefferson had noted over two centuries previously, become President for life, which would abrogate the democratic principles of the country, and potentially eliminate the form of government itself.
Consequently, the 22nd Amendment was proposed and ultimately passed Congress, and was ratified by virtually all of the states. the 22nd Amendment says that one Person cannot serve as President for more than 2 terms, or 10 years total. (The 10 years total bit allows for a person to be a Vice-President and succeed a President for up to two years of that President's term, and then still be elected to two terms in his or her own right). The easy way to remember what the 22nd Amendment does is to recall that it stands for "2" and only "2" terms, (with the two "2s" making 22nd). Thus, ever since 1947 when the Amendment was ratified, a President cannot serve more than 2 terms. There have been attempts on both sides of the aisle to repeal the 22nd, which movement started ultimately with Ronald Reagan in the 80s, but continued after as well.
The reason that the Presidency is subject to term limits but legislators are not ultimately comes down to the sharing of power. There is only ONE President at the time, while there are 435 Congresspersons and 100 Senators. Thus, even if a Congressperson or Senator is elected repeatedly, there is little danger of an "Imperial Senator" or "Imperial Congressperson" because that person's share of power in the institution is either 1/100 or 1/435.
I hope that answers your question with some historical context thrown in as well.