Is adultery illegal? Is divorce illegal? It is not prostitution that is the problem in the situation you describe; it is husband who abandon his family.
on top of the obvious contribution to breakup of families which it contributes to - the monetary component adds the element of oppression/slavery.
many prostitutes are slaves to their pimps and the johns provide the demand for the slavery.
I don’t think people often want to stop and think of prostitutes as human beings who are being held as slaves, but that is often the case.
Add in the disease component and there’s plenty of reason for a society to deem it enough of a threat to make it illegal.