As I mentioned here, three presidents had significant service in public office after leaving the White House.
The second such president was William Howard Taft. He was the only person to head up both the executive and judicial branches of the federal government.
Taft was unusual in that he was one of three 20th century presidents who had never been elected to any public office before becoming president. However, as was the case with the other two such presidents, Herbert Hoover and Dwight Eisenhower, Taft was appointed to high-ranking government jobs. He was a prosecutor, solicitor general, judge, governor-general of the Philippines, and secretary of war.
When Theodore Roosevelt declined to run for a second full term in 1908, he anointed Taft as his successor, and Taft easily won that year's presidential election. But he had a difficult term. Perhaps it was his lack of experience in elected office that left him as a bit of a fish out of water in the presidency.
In 1912, largely due to Roosevelt's comeback attempt, Taft suffered the indignity of being the only presidential nominee in the history of the Republican Party to finish in third place in a general election.
During the next few years, Taft taught at his alma mater, Yale, and did extensive writing.
By 1921, Taft's Republican Party was back in control of the White House and the Congress. When Chief Justice Edward White died in 1921, President Warren Harding appointed Taft to be chief justice of the United States. Taft continued in that role until he retired, shortly before his death in 1930.
Here is a brief overview of the Taft Court, from the Supreme Court Historical Society.
Taft's judicial legacy largely involves procedural and organizational reforms. Perhaps the most significant of those reforms was legislation for which he advocated, by which Congress gave the Supreme Court the right to decide which appeals it would and would not consider. Under the new system, still in use today, a party that wants to appeal its case to the Supreme Court must petition for a writ of certiorari, which is legalese for a decision on the part of the court to hear the appeal. Previously, the court was obligated to hear every appeal brought to it; as the country grew, the caseload became more unwieldy.
Taft also successfully pushed for the Supreme Court to get its own building. Previously, it had met in the Capitol, and the justices had done most of their work in their individual homes. The decision to build the new structure was made while Taft was chief justice, with strong lobbying on his part; but it was constructed after his death, and was completed in 1935.