بسم الله الرحمن الرحيم
(Fatwa: 762/730/SN=7/1438)
The status of impurity in janabah is not Haqiqi rather it is Hukmi. Hence if at the time taking of janabah ghusl i.e. fardh ghusl – the water touched with the body or foam of the soap falls in the water or smears with the clothes then the cloth and water does not turn impure provided the falling water or foam is free from visible impurity i.e. semen etc. So in the question mentioned above if no visible impurity such as semen etc is mixed in the foam then the water in the bucket shall not turn impure rather it shall be deemed pure as usual.
وإن انتفح من غسالة الجنب في الإناء لا يفسد الماء الخ. (كبيري، ص: 133، ط: دارالكتاب)
Allah knows Best!
Darul Ifta,
Darul Uloom Deoband