It's the Electoral Count Act.
So a bit of a background here: after the Election of 1876, Samuel Tilden had been leading the popular vote and leading the electoral college, but because of three states in dispute, basically conservative Democrats and pro-Reconstruction Republicans engaging in voter fraud and ballot stuffing, there was no 12th Amendment contingent election. Therefore, it shifted to what was supposed to be a bipartisan election commission, but the SCOTUS judge dropped out and it left 7 Republicans and 7 Democrats... who ended up tying. (Of course, this was resolved in the Compromise of 1877—liberal Republicans agreed to appease conservative Democrats by ending Reconstruction on the promise that conservatives would not infringe on Black civil rights. In true conservative fashion, they broke their promises and ushered in right-wing apartheid known as Jim Crow.
The Electoral Count Act (and additional provisions in Title 3 of the US Code) was passed in 1887 in response to what happened in 1876. For brevity (you can find the full explanation of the law in on lawfareblog.com, but I'll limit it to the example I made in my comment you're replying to:)
Scenario A:
(A) A state sends two slates of electors; one that was certified by the governor in accordance to state law and another slate of rogue electors—say, sent by a state legislature (which technically cannot happen unilaterally because Article 2 doesn't explicitly say that state legislatures can do this unilaterally)...
(B) The House and the Senate both have to agree on which are the legitimate slate of electors. Keep in mind, this takes place on January 6th. Kelly Loffeler and David Perdue's terms end on January 3, 2021. Their Senate election is on January 5, 2021. They will not be seated before Congress meets to formally count the electoral college votes on January 6, 2021. This leads to a 98-member Senate with 50 Rs and 48 Ds.
(C) Typically the slate of electors as appointed by the governor gets favored. However, that has to be agreed upon by both houses of Congress. You already got five Republicans on record acknowledging that Joe Biden won the election (Romney, Toomey, Murkwoski, Collins, and Sasse) and only 3 of them need to side with the Democrats (who will more than likely will be Murkowski, Collins, Romney; would not be surprised if Toomey does too considering he's retiring).
(D) In this scenario, if Collins, Murkowski, and Romney or even Collins, Romney, or Toomey all agree that the Biden slate electors are the legitimate ones, they will side with Pelosi and the House Democrats. If they do not agree, then the electoral votes are not counted and a House Democrat and a Senate Democrat, in writing, can object to all other electors and drag it out as long as they wish.
Scenario B:
(A) A House Democrat and a Senate Democrat object to a rogue slate of electors.
(B) Both the Senate and the House separately debate that slate of electors for two hours.
(C) If the House Democrats uphold the objection, but the Senate votes against the objection, then objection is overruled; however, I doubt this happens considering Romney, Collins, Toomey, Sasse, and Murkowski all recognized Biden as the winner and only 3 of those 5 have to side with Senate Democrats in upholding the objection. If the objection is upheld, then the votes are not counted.
(D) In the event that the whole Electoral College is NOT counted, in either scenario, there is no contingent election. Theoretically, this can continue to be dragged out as well by Pelosi.
So:
Donald Trump and Mike Pence's terms STILL end on January 20. Because there is NO contingent election in the event of a disputed electoral college in Congress, Nancy Pelosi becomes the Acting President of the United States on January 20th and she can decide to nominate a Vice President to preside over the Senate. She remains acting President until an actual President is chosen.