Gurudev, Yudhisthira (the eldest of the five Pandava brothers in the Mahabharata) used to gamble. He gambled and lost his wife (Draupadi) in a game of dice. Then why is he given the title of ‘Dharmaraj’ (the supreme upholder of Dharma or moral virtues)?
In those days, gambling was not considered a bad thing. Just like how today there are licensed bars, and government sanctioned liquor shops which have the permission to serve alcohol.
In the same way, gambling was considered to be a sort of game or sport of the kings.
You need to understand that it is not that whatever Yudhisthira did was all correct. You cannot think like that. In fact I would say what he did was very wrong. But because his heart and mind were pure and there was no malice or sinful thought in his mind, he had the support of the Lord with him.
Also, if he had not played the game of dice, then how would all those problem arise? How would the Mahabharata take place? If, as Dharmaraj he had refused to play the game of dice, then there would have been no problem at all.
See, any person, even if he or she upholds very high human values, when they acquire some position of power, you will find some or the other flaws in them.
Moreover, Yudhisthira was not a sanyasi (a renunciate), he was a worldly man. And it is only natural for someone who is a worldly person to have some flaws. To become completely blameless and turn into a sanyasi is a different thing altogether.
So even as a king, he did have some flaws, like the habit of gambling. He simply could not refuse an invitation to gamble. And had he refused, the Mahabharata would not have happened, the Pandavas would not have gone into exile and Draupadi would not have had to undergo so much suffering (referring to the attempt of disrobing of Draupadi in the royal court). And had all this not happened, then the Mahabharata too would never have happened, and we would have never had the Bhagavad Gita.
Then Lord Krishna would not have had anything to do! He would have simply enjoyed his time eating butter in Vrindavan, and he would have never left the place (Laughter). There would have been no need for him to leave Vrindavan at all.
Wherever Lord Krishna went, there was surely some mischief or chaos which he would try to resolve.
This is why all this is called as His Leela (pastimes or divine play of the Lord).
So there is no use criticizing whatever happened, and neither is there much to be gained by over-analysing these events. It is not an intelligent thing to do. You must see all of this as the Leela of the Lord. Then you will find that there is a treasure chest of wisdom and knowledge to take away from it. Knowledge that is so useful and practical for life.