First of all if you are a winning player, you should buy in for the table maximum and use auto top-up, so that you are always sitting with the table maximum. Most commonly that is 100BB, but sometimes it can be more. In ACR BLITZ (fast fold) it is 120BB for instance, and GG Poker has a big ante game, where its 200BB. The reason for this is, that playing with a deeper stack give the highest potential winrate, and it also simplify things, because you can focus mainly on your 100BB strategy and not on 40BB strategy and everything in between.
In the past there were some regulars, who bought in for 40BB as a deliberate strategy called cap stacking, but this has largely gone out of fashion, and I dont recommend it. But IF you were to do this, then you should probably leave after dubbling up, because otherwise you are not really playing a cap stack strategy anymore. This is also one of the reasons, why I dont recommend it, because it sucks to leave a good table, just because you won a pot. And most sites have some sort of anti ratholing policy, which mean, that if you were to join the same table again within an hour or so, then you would be forced to buy in for the amount, you left with.
So assuming, you bought in for 100BB, when should you then leave? For me the main answer is, when the table is no longer good. In a cash game you should always be able to identify at least 1-2 players, who are significantly worse than you. And if you cant, maybe because they got stacked and left, then its also time for you to leave.
The other situation is, if another good player to your left is also sitting with a large stack, so that you are perhaps 250BB deep against that player but only 50BB against the bad players. This is an unprofitable situation, which is it reasonable to decline being part of. A final situation is, if you are sitting with more than 5% of your total
bankroll, and someone else have you covered. Then its reasonable to leave for risk management reasons.
But in general I love playing with a big stack, because it gives a good "table image", where often other players will try to stay out of your way. So rather than leave tables to "lock up a win", it often makes sense to do the exact opposite and stay on tables, where things have been going your way but leave those, where they have not. A bit like the stock investment strategy of "keep your winners but dump your losers".
The situation, where I will most commonly leave to "go south", is in fast fold style games like Zoom on
pokerstars. The reason is, you can easily join the same player pool again with 100BB (or 120BB on ACR), and I dont feel, that I have an edge in these games playing with a 200+ BB stack. Which will happen quite commonly, since many players build up big stacks.