The gifts come from Mr. Musk’s political organization, which aims to boost Donald Trump’s presidential campaign.
Philadelphia District Attorney Larry Krasner, a Democrat, filed a lawsuit Monday to stop America PAC’s sweepstakes.
The lottery will continue until Election Day on Tuesday.
Judge Angelo Follietta will hear motions on the matter in a City Hall courtroom.
Matthew Haverstick, one of several lawyers representing the defendants, declined to say late whether Mr. Musk would attend the hearing.
The lottery is open to people in battleground states who sign a petition in support of the Constitution.
Mr. Krasner said he could still consider criminal charges, saying he was tasked with protecting the public from both illegal lotteries and “interference with the integrity of elections.”
Voting law experts have raised questions about whether the scheme violates a federal law prohibiting someone from paying others to vote.
Mr. Musk has designated the money as both a reward and a perk for serving as the group’s spokesman.
In the lawsuit, Mr. Krasner said that America PAC and Mr. Musk “are in undisputed violation of Pennsylvania’s statutory prohibitions against illegal sweepstakes and consumer fraud.”
Both Mr. Trump and his Democratic rival, Vice President Kamala Harris, have made repeated visits to the state as they battle for Pennsylvania’s 19 electoral votes.
Mr Musk, who founded SpaceX and Tesla and owns X, backed the former president, saying he believed civilization was at stake if he lost.
He is undertaking much of the get-out-the-vote effort for Mr. Trump through his super PAC, which can raise and spend unlimited amounts of money.
He has given more than $70 million (£54 million) to super PACs to help Trump and other Republicans win in November.