Trump was beating the ‘stolen election’ drum well before the actual election. He definitely expected to lose.
That said, if he hadn’t he could have just kicked the can down the road.
It was a suckers bet for Biden to win, because any attempt to change this (and there wasn’t much) was going to get blocked. Just like Afghanistan.