LEXINGTON, S.C. — The Facebook profile picture chosen by Dylann Storm Roof in May is thick with symbolism. It shows Mr. Roof, a scowling young white man, wearing a black jacket adorned with two flags — one from apartheid-era South Africa, the other from white-ruled Rhodesia — that have been adopted as emblems by modern-day white supremacists.

Mr. Roof, 21, was arrested Thursday in North Carolina after law enforcement officers identified him as the suspect in the mass shooting at a black church in Charleston, S.C., on Wednesday night. The shooting left nine dead, including the pastor, the Rev. Clementa C. Pinckney.

Officials said the shooting was being investigated as a hate crime. Although it was not clear if Mr. Roof had actually joined any organized white supremacist groups, people who knew him said that in recent months, a young man they described as extremely shy had begun to harbor racist views and make increasingly violent statements about attacking black people.

Joseph Meek, 20, a childhood friend who reconnected with Mr. Roof this year, said Mr. Roof had changed, spewing racist ideas and talking about wanting “to hurt a whole bunch of people.”

“He was saying all this stuff about how the races should be segregated, that whites should be with whites,” Mr. Meek said. “I could tell there was something inside him, there was something he wouldn’t let go. I was trying to tell him, ‘What’s wrong?’ All he would say was that he was planning to do something crazy.”