but when is the best time to stop gambling and take a break?
1-when you lose?
2- when you win?
It will be foolish to take a break from gambling when you win, the only issue here is when the gambler continues to gamble due to overconfidence and greed, then it's time to take a break. But there is no problem if he has a plan and sticks to it, winning should never be the barrier. However, such a gambler is not taking the break because of the "win" but for the emotion that has taken hold of him.
As for losing, it's better you also take a break if you are becoming increasingly desperate to gamble, especially if it has turned into a revenge quest that has led to addiction.
You can call it foolish, but in my opinion, taking a break or logging out the casino when one is winning is one of the best strategies to pull off, but at the same time it is the hardest to stick to due to the effects greed can have over the person's psyche. It takes much control to know when it is true to withdraw an call it a day, while one is having a lucky streak. It will be easier for those who immediately recognize those streaks not to last long and be eternal.
If we are supposed to talk about foolishness, then I would be abliged to do the same other have already done and point at those gamblers who chase their losses or believe they could find a way to beat the casino in a systematic way.

Foolishness is not withdrawing the money when one is winning, is actually the paramount of self-control against greed.