Non American here. Have there ever been a US president who was a convicted felon and served time for it before taking office? If not, why not?
No president has been convicted of any felons and/or served time for it before taking office. It's difficult to provide a source stating that something does not exist or in this case, that something has not happened so I do apologize. I can elaborate more into felons and their relationship to the presidential position in the United States though.
Article II, Section 1 of the constitution states that any natural born citizen of the United States is eligible to become president.
No Person except a natural born Citizen, or a Citizen of the United States, at the time of the Adoption of this Constitution, shall be eligible to the Office of President; neither shall any Person be eligible to that Office who shall not have attained to the Age of thirty five Years, and been fourteen Years a Resident within the United States.
Notice how this does not discriminate against felons or any other individuals except those who are not a natural born citizen. Felons can run for office and have run for office in the past. Rick Perry, who recently dropped out of the presidential election, had three felony charges against him. One of which was dropped back in July. I don't know what is going on with the other two charges but, if he was convicted he would then be a felon and be running for presidency. Interestingly enough, this actual boosted his ratings by about 7% according to a Public Policy Polling (PPP). A famous case of this happened in 1920 when Eugene Debs ran for president from a prison cell. He earned 914,191 (3.41%) of the popular vote. Not enough to win but more than any other felon to date.