It is true nowadays that party nominees who lose the election do not run for the presidency again.
However, in the first six decades of the 20th century, there were many examples of presidential nominees who campaigned again in subsequent elections.
William Jennings Bryan was the losing Democratic nominee in the election of 1896, but he went on to gain the party nomination again in 1900 before losing to William McKinley second time. He declined to contest the 1904 primary, but did compete in 1908 and once again secured the Democratic party nomination before losing a third time, this time to William Taft.
Al Smith was the Democrats' nominee in 1928, losing to Herbert Hoover. He ran again for the nomination in 1932, but lost the nomination to Franklin Roosevelt.
Wendell Willkie was the Republican nominee in 1940, losing to FDR. He ran briefly in 1944 but fared poorly in April primaries and dropped out of the race.
The winner of the 1944 Republican nomination, Thomas Dewey, went on to lose FDR as well, but fared better than Herbert Hoover, Alf Landon or Wendell Willkie had in their contests. Dewey would go on to secure the 1948 Republican nomination, and ran a very strong campaign. He looked so certain to defeat incumbent president Harry Truman, the Chicago Daily Tribune famously ran the erroneous headline Dewey Defeats Truman.
In the 1952 Democratic primary, Adlai Stevenson won the nomination before losing to Eisenhower. In 1956 Stevenson again secured the nomination, but was again defeated by Eisenhower. Despite both of those defeats, Stevenson once again contested the 1960 primary, but finished in 4th place at the convention.
In 1968 it was not at all unusual for a candidate with Nixon's history to run again in subsequent elections. Nixon was considered a possible candidate in 1964 before he announced at the convention that he would not run and supported Barry Goldwater. Nixon was unusual in that he managed to win the election the second time around.
So, how is it that these nominees could win nomination again after electoral defeats?
Well, party primaries and party conventions used operate very differently than they do now. It used to be that only 10 or 12 states would hold ballot primaries, while the other 36 or 38 states would hold caucuses. Where a primary can be a brief affair of waiting in line and casting a ballot, a caucus can require all-day participation of caucus voters. Edit: that usually means the most committed voters turnout for caucuses to support their candidate, compared to low-effort voting. /edit. Also, up until 1968, state and county party chairs had broad discretion in determining eligibility to participate in a caucus or eligibility to be elected a delegate from a caucus.
Conventions also operated very differently. It was a common occurrence for "favorite son" candidates representing important states like New York, Pennsylvania, Illinois, California, to run campaigns only in their state, and go into the convention expecting to bargain their delegate support to national candidates in exchange for policy concessions and perhaps a cabinet post.
In the era before 1968, brokered conventions happened regularly, where deals in "smoke filled back rooms" between party bosses determined who delegates would put their support behind.
So, for candidates like Bryan, Dewey, and Stevenson, their first nominations came from a mix of factors such as perceived electability, national stature, and their appeal to a broad swathe of a party instead of one particular wing or faction. Often, having personal relationships with party bosses from the various state delegations was of critical importance in securing the nomination.
So, once these candidates secured the nomination, they would continue to cultivate these relationships with party bosses to ensure control over state party machinery. By maintaining loyalty of state party bosses, these candidates could put a thumb on the scale in the next cycle's primaries and caucuses. With control over party machinery at the convention, they could put themselves in position for their second nomination.
However, Richard Nixon did not really follow that template. He declined to run in 1964, so in 1968 he could no longer claim to be the undisputed head of the party. Instead, he quietly began to organize his campaign for presidency 18 months before the convention, putting lots of effort into campaign organization for the early primary states. By organizing early before his opponents George Romney, Nelson Rockefeller and Ronald Reagan, he managed to win several early primaries and caucuses, and position himself as the front-runner candidate at the convention.
This era of brokered conventions and back room deals ended after 1968, in large part because of the 1968 Democratic convention in Chicago. That convention saw multiple controversies, including competing slates of delegates from southern states. One batch of delegates was racially integrated, the other batch not, and the controversy concerned which slate of delegates should be accepted as the official slate of delegates.
Another controversy was the fight between the hawkish wing and dovish wing of the party. Hubert Humphrey was serving as Lyndon Johnson's vice president, and was the strongest Democratic candidate who supported continuing the war in Vietnam. Anti-war candidates like Eugene McCarthy and George McGovern entered the convention drawing their support from victories in the primaries. Humphrey did not campaign in the primaries, instead relying on a strategy of relying on party apparatus to ensure delegate accumulation in the caucus states.
When Hubert Humphrey ended up securing the convention, it provoked protest from young anti-war activists outside the convention, which were then subjected to a police riot by the Chicago Police department. It seemed to be that Chicago mayor Charles Daley Richard M. Daley allowed the police "off the leash" to punish protesters for embarrassing Daley's ally Humphrey. Many in the anti-war wing of the Democratic party felt snubbed by the undemocratic result of the convention where Humphrey was made nominee despite not campaigning in the competitive primaries. These divisions, plus divisions between the civil rights wing and segregationist wing of the party in the south contributed to Humphrey's defeat.
In response to the shameful debacle at the 1968 Democratic National Convention, and Humphrey's loss to Nixon, the Democratic party empowered the McGovern-Fraser commission to consider reforms to the primary and convention process. McGovern-Fraser commission recommended increasing the number of ballot primaries, and reforms which decreased the influence of local party bosses to determine slates of delegates out of caucuses. It also required candidates at convention to have delegates from more than one state, which eliminated the phenomenon of "Favorite Son" candidates.
Since 1972, the trend for both political parties has been for an increasing number of states to hold ballot primaries rather than caucuses. In 1968, 13 states held ballot primaries and the remaining 37 held caucuses or allocated delegates by state convention. In 2020, 46 states + DC and Puerto Rico held primaries, while only 4 states and 4 territories held caucuses or straw polls. It also means that results of primaries translate to pledged delegate allocations, and delegate tallies are known weeks in advance of the convention.
With those changes, primary campaigns have become much more competitive and more democratic, and nominees who have lost a presidential election have, so far, been unable to secure a second nomination.
Edit to mention: Hubert Humphrey did run for election again in 1972. However, George McGovern resigned his chairmanship of the election reform commission to also run for president in 1972. Having had a hand in writing many of the reforms, McGovern had an advantage in campaign strategy, coupled with the energetic support of young Democrats, that he rode to the nomination.