It varies by state. For Pennsylvania we have Section 980 and 981 of the PENNSYLVANIA ELECTION CODE (pdf):
Section 980. Substituted Nominations by Political
Bodies. -- In case of the death or withdrawal of any candidate
nominated by any political body by nomination papers, the
committee named in the original nomination papers may nominate
a substitute in his place by filing in the proper office a
substituted nomination certificate, which shall set forth the
facts of the appointment and powers of the committee (naming
all its members), of the death or withdrawal of the candidate
and of the action of the committee thereon, giving the name,
residence and occupation of the candidate substituted thereby,
and the truth of these facts shall be verified by the affidavit
annexed to the certificate of at least two members of the
committee.
Note: "political body" refers to the recognized parties in Pennsylvania. For Pennsylvania this is the Democratic, Green, Libertarian, and Republican parties.
So it would be up to the Pennsylvania Democratic Party to choose a replacement candidate. This could be a "smoke filled room" type affair, though presumably they could get input from registered democrats in the state through informal means. It's also possible the Pennsylvania Democratic Party has pre-established procedures for what happens (eg: the second place primary candidate takes their place).
However, there is a time limit for this process:
Section 981. Time for Filing Substituted Nomination
Certificates. --(a) Substituted nomination certificates to fill
vacancies caused by the withdrawal of candidates nominated at
primaries or by nomination papers shall be filed with the
Secretary of the Commonwealth or proper county board of
elections, as the case may be, at least seventy-five (75) days
before the day of the general or municipal election
Assuming I counted right, that would mean the replacement would need to happen before Aug 25. Although I don't have a citation on hand, if the death to happen after that date his name would stay on the ballot. In that case, if he were to still win*, a special election would follow the November general election.
*Dead people occasionally win elections -- for example it happened to George W. Bush's Attorney General John Ashcroft -- https://en.wikipedia.org/wiki/2000_United_States_Senate_election_in_Missouri