Let me begin with a story. I am white and my husband was African-American. I worked for an agency that was approximately 50% white and 50% African-American. The first Christmas I worked for this agency, my husband and I attended the Christmas party. When we arrived at the restaurant, we were quite dismayed to see that all the African-American employees were sitting at one table and all the white employees were sitting at another. We decided we would simply have to take turns at the two different tables.
This was clearly voluntary racial segregation. We would all like to think that but for a history of slavery, racism, and Jim Crow laws in the United States, people would never voluntarily segregate themselves by race. But they do. And people socially segregate themselves in other ways as well. Private clubs are a classic example of this, as often people's housing choices are, too. Historically black colleges are yet another example.
Why do we do this? I think there was an evolutionary advantage in being able to keep away those not of one's tribe, the "other" who could be a danger. This served us well for tens of thousands of years. The problem is that civilization has evolved in a way that makes the tribal distinction meaningless, while we persist in this "instinct" in ways that are now counter-productive, still functioning with the tribal mentality.
Clearly, social segregation can be involuntary as well. Just look at any high school to see this operating. The jocks shun the nerds. The jockettes shun the unpopular girls, whose unpopularity might be based upon their socioeconomic group, their ethnicity, or some other social attribute. This is one reason schools like to require uniforms, to try to do away with this involuntary social segregation. Public housing is another form of involuntary social segregation. If we wanted to do away with this form of segregation, we would give people vouchers and let them live where they pleased. (There are housing programs that do this, but there are always long waiting lists.) And there is no question that most racial segregation has been involuntary, historically, a matter of law.
So, to answer the question, social segregation can be voluntary or involuntary. There is no way to legislate against voluntary segregation, and aside from the legislation that does away with involuntary legislation for a short list of protected classes, people will continue to be involuntarily socially segregated. Unless, perhaps, we evolve.