"If the Republican candidate dies or is incapacitated after the convention and before Election Day, the Republican National Committee (RNC) will meet to select a presidential candidate and/or vice-presidential candidate under Rule 9 of party rules.
...
The Democratic National Committee (DNC) is also authorized to select the party’s nominee in the event that the winner of the convention cannot run. This is spelled out in the charter of the Democrat Party. However, since DNC members are awarded to states according to the size of the states, there would be no adjustments.
...
If the candidate dies or is incapacitated after Election Day, the Constitution kicks in. The first milestone will be the December 17, 2023, meetings of the electoral college. It may surprise many to know that the electoral college is composed of real flesh and blood electors who meet in their state capitols and sign documents (attestations) that are forwarded on to the president of the Senate (the vice president) for the purposes of counting only! We only hear about electors when someone decides to make a point and vote for someone whose slate they were not on. (During segregation some of these so-called “faithless electors” voted for segregationist candidates.1) Some states have laws binding electors to vote for the winner of the election, others do not. If the winner of the convention dies or is incapacitated it is likely that the legislature would quickly meet to amend the law so that their votes would count.
Finally, what if the president-elect dies or is incapacitated after the electoral college meets and before the inauguration? The authors of the 20th Amendment to the Constitution, the one adopted to provide for a way to pick a new vice president, thought of this. If the president-elect dies or is incapacitated the vice president is inaugurated. Section 3 of the 20th Amendment reads:
“If, at the time fixed for the beginning of the term of the President, the President elect shall have died, the Vice President elect shall become President.”"
https://www.brookings.edu/articles/what-happens-if-a-presidential-candidate-cannot-take-office-due-to-death-or-incapacitation-before-january-2025/