This is a very good question, and one that has undoubtedly troubled many readers over the years. Here is a copy of the dialogue you refer to.
"It's not true! I'll bet you two million you wouldn't stay in solitary confinement for five years."
"If you mean that in earnest," said the young man, "I'll take the bet, but I would stay not five but fifteen years."
The lawyer seems crazy if he could win the two million rubles in five years and elects to stay in solitary confinement for fifteen. It could be attributed to youthful bravado. This is an all-male party where there would certainly be a lot of drinking done. The men would be drinking vodka and wine, and all of them would be inebriated. This might explain the lawyer's bravado. It is noteworthy that Chekhov does not say a single word about liquor or about intoxidation. He must have wanted to avoid giving the impression that both the banker and the lawyer were showing off because they were drunk. Chekhov has invented a preposterous story, and his hardest problem is to make it credible that two men would make such a bet. They might bet anything if they were drunk, but they would cancel the bet when they were sober.
Chekhov wants to assure the reader that this is a bona fide bet. He has the banker approach the lawyer later and try to persuade him to back out.
"Think better of it, young man, while there is still time. To me two million is a trifle, but you are losing three or four of the best years of your life. I say three or four, because you won't stay longer. Don't forget either, you unhappy man, that voluntary confinement is a great deal harder to bear than compulsory. The thought that you have the right to step out in liberty at any moment will poison your whole existence in prison. I am sorry for you."
The banker, an older man, is sorry he made the stupid bet. He does not like the idea of keeping a man in solitary confinement on his own estate for a number of years. But he does not want to back out himself. He would like the lawyer to do the backing out. The banker has made the bet in front of a big gathering of important men. If he were to back out unilaterally, as he probably could do, he would feel humiliated. Not only would the guests feel contempt for him, but they would tell the story in other social gatherings, and the banker's shame would be spread all over Russia.
But the lawyer insists on going through with this "wild, senseless bet." It seems likely that he raised the stakes, so to speak, because he wanted to make sure the banker would go through with his proposition. Note that the lawyer says, "If you mean that in earnest." The lawyer wanted to make the banker feel that he was sure to win, whereas if the term of imprisonment were only for five years, the banker could not be at all sure of winning. That seems to be the lawyer's main reason for raising the term from five to fifteen years. But the lawyer was probably drunk when he said it, and he may have regretted imposing another ten years on himself when he might not have needed to do so. However, like the banker, the lawyer had made the bet in front of a number of important men and didn't want to be disgraced either. The banker was showing off how rich he was, and the lawyer was showing off how strong-willed he was. At the time, the money meant a lot to the lawyer. He wanted the banker to mean the bet seriously and to stick to it.
As a result of all the dickering about the bet, the reader himself becomes convinced that the bet is serious and binding. This may have been Chekhov's main purpose. His hardest job as the author of this weird tale is to convince the reader that both men are sincere. Chekhov starts off the story with a flashback. The fifteen years are already up. That seems to prove that the bet was binding on both parties. The only problem is that the banker would now find it very hard to raise two million rubles. This is such a problem that he is planning to kill his prisoner rather than pay him.