If everybody was to vote on their ballot for a United States president who had already served two terms and won the election what would happen?
There are two possible scenarios: The Vice-Presidential President and a mass Write In.
In the first, if the elected President is removed from office after 2 years in office, than the Vice-President (and the entire eligible line of succession for that matter) would be eligible to run for two terms, giving the Former Veep the ability to serve for a total of 10 years. If the Veep ascends to President prior to the 2 year mark, it counts as his first term for 25th Amendment Purposes and he can only run for one more election.
In the second scenario, if there is a mass write in campaign of a former two term President that wins, the votes will not be counted as the candidate is not eligible under the terms of the 22nd Amendment. Under Article II of the Constitution, no person who is ineligible from office may ever ascend to the office of President. In terms of the 25th Amendment, the Presidential Line of succession currently is starts with the Vice-President, than the Speaker of the House, than the President pro-tempore of the Senate, followed by the Cabinet by order of Creation of office.
Only the Vice-President is exclusively barred from being a non-Native Borne U.S. citizen. However, the rest of the offices in the succession line are not barred in such a manner, so there could arise a case in which the line has a member who is not a native born citizen (Currently Secretary of Transportation Elaine Chao is a naturalized citizen and not eligible to become President. Were she eligible, she would be 14th in line.). As such, she is omitted per the Presidential Succession Act and the line below her is elevated. She is also disqualified from being a Designated Survivor, as they role entails that they must be legally authorized to be President should the worst happen.
This would have to be settled in the courts. Ultimately the person could not serve, because of the 22nd amendment ("No person shall be elected to the office of the President more than twice, and no person who has held the office of President, or acted as President, for more than two years of a term to which some other person was elected President shall be elected to the office of President more than once"). "Be elected" does not mean "stand for office" (there is a 2-term limit on serving, not running).
Each state specifies how the president will be selected therein (via the state's electors), so it would require a 50-state search of laws to see whether there are limitations on standing for office if a candidate is legally barred from holding the office, if they gained the required number of votes. Washington state does not impose restrictions on candidates for any office – one down, 49 to go.
It is probable that in each state, someone would file suit to block the inclusion of said candidate on the ballot, although the secretary of state might preemptively decide that the candidate will not be listed (and then someone else would sue to force the name to be included on the ballot). Courts could differ in their decisions, based on the facts of state electoral laws and constitutions, not to mention judicial ideology (i.e. how inclined the court is to allow symbolic acts). After the election, the electors would also have to decide whether to symbolically cast a vote for a guaranteed non-president. These votes are tallied by Congress, under the 12th Amendment, and assuming the person gets a majority of the votes, that person "shall be the President". The 22nd Amendment exception, however, is later (supersedes the 12th). Art. II Sect. 1, Cl. 6 of the constitution says
In Case of the Removal of the President from Office, or of his Death, Resignation, or Inability to discharge the Powers and Duties of the said Office, the Same shall devolve on the Vice President
and the 25th Amendment says
In case of the removal of the President from office or of his death or resignation, the Vice President shall become President
If states attempted to impose limits on candidates for federal office, they could face some opposition from SCOTUS. U.S. Term Limits Inc. v. Thornton would be potentially applicable. In this case, Arkansas had a law which prohibited putting on the ballot any candidate who had served 3 terms. The court found that that law violated the US constitution. The court held that "the Constitution prohibits States from imposing congressional qualifications additional to those specifically enumerated in its text" – however, this particular (dis)qualification is in the constitution, thus state laws preventing constitutionally-blocked candidate from appearing on the ballot could well pass SCOTUS scrutiny.