No rush! 4 months if you HAVE to, like the mare is ill or somehting.
6 months is also a bit on the early side, but at least the foals will have gotten used to eating enough on their own so they won't loose weight during weaning.
I prefer if the foal is not sold, to keep the foal with the mare until at least 8 months. Not until then the foals intestins are developed enough to be able to feed on their own.
If my mare is pregnant again I don't have to worry, she weans her baby herself at about 8-10 months of age!
The absolut most important before weaning is that the foal is in good health, have enough fat and can eat the calories they need by themselves.