The bet originated at an all-male party given by the banker. The narrator does not mention alcoholic beverages, but it seems extremely likely that at such a party there would be a lot of drinking being done. There would be vodka before the meal and wine with the food. This seems like the only probable explanation for two men making such a bizarre bet. Chekhov did not want the reader to think that the bet was only made in a spirit of bravado by two intoxicated men. Therefore, he inserts a passage in which the banker, presumably sober now, tries to talk the lawyer into backing out of the bet.
"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."
Now the two men seem to be stuck with a bet they would not have made if they had been sober. For the banker it is a matter of pride. He does not want to be the one to back out. For the lawyer it is a matter of pride, but it is also a matter of money. He stands to win a fortune of two million rubles if he can remain in solitary confinement for fifteen years. Somehow or other, the argument about capital punishment versus life imprisonment has evolved into a bet that the lawyer cannot stand solitary confinement for fifteen years. Nothing was said about solitary confinement when all the guests were arguing. But Chekhov seems to have changed the bet because, obviously, the banker would have no way of keeping a man in prison for life, especially when the lawyer was only twenty-five years old and the banker was close to twice his age. Furthermore, no one could agree to spend life in prison no matter how much he might win. He would not collect until he was dead!
The bet is close to being preposterous. The author has a hard time convincing the reader it really happened. He has the banker himself reflecting on how foolish both he and the lawyer were to let their pride incite them into making such a bet. The fact that there were many prominent guests present when the bet was made helps to explain why it was difficult for the banker and the lawyer to cancel it after it had been formalized.
And now the banker, walking to and fro, remembered all this, and asked himself: "What was the object of that bet? What is the good of that man's losing fifteen years of his life and my throwing away two million? Can it prove that the death penalty is better or worse than imprisonment for life? No, no. It was all nonsensical and meaningless. On my part it was the caprice of a pampered man, and on his part simple greed for money ..."
The short answer to the question, "Why did the lawyer and banker agree upon the bet?" is that "It was all nonsensical and meaningless....it was the caprice of a pampered man, and on his part [the lawyer's] simple greed for money." But both men must have been intoxicated when they originally made the admittedly fantastic bet. It is strange to imagine a man keeping a prisoner in solitary confinement right on his own grounds, where he could see the lodge every day and know that the lawyer must be silently suffering even while doing his best to pass the time and make the most of it.
Chekhov takes considerable pains to make the bet appear iron-clad. It is no coincidence that the prisoner is a lawyer. If the banker should refuse to pay him at the end of fifteen years, the lawyer could sue him for damages. There were certainly plenty of witnesses to the verbal contract the two men made during the party. Chekhov describes the group briefly.
The majority of the guests, among whom were many journalists and intellectual men, disapproved of the death penalty. They considered that form of punishment out of date, immoral, and unsuitable for Christian States.
If the banker refused to pay the two million rubles, the journalists would spread the story of his dastardly behavior all over Russia. The banker would be disgraced forever--and he would still end up having to pay the money.