By Harriet McLeod

CHARLESTON, S.C. (Reuters) - A U.S. judge on Monday ruled Dylann Roof was mentally fit to serve as his own lawyer in the penalty phase of his trial, when a jury will decide whether to sentence him to be executed for the 2015 massacre at a South Carolina church.

Roof, 22, an avowed white supremacist, was found guilty in December on all federal charges in the shooting deaths of nine black parishioners at Emanuel African Methodist Episcopal Church in South Carolina in 2015.

The shooting where Roof had waited for members of a Bible study group to close their eyes in prayer before opening fire sent shockwaves across the United States.

The same jury that convicted him of 33 charges that included hate crimes resulting in death will meet on Wednesday for the penalty phase, where they will decide whether he should be executed.

U.S. District Judge Richard Gergel issued his ruling after hearing testimony from forensic psychiatrist James Ballenger, who examined Roof for five hours over the weekend.

Gergel had kept the competency hearing closed in order to avoid sequestering the jury.

Gergel said he was concerned jurors would inadvertently hear potentially prejudicial information from the hearing if reporters were allowed to cover it, ruling that protecting Roof's right to a fair trial outweighed the media's right to view the hearing.

The judge rejected arguments from press attorney Jay Bender and Assistant U.S. Attorney Jay Richardson, who wanted an open hearing. Gergel also banned relatives of the victims from attending.

The judge previously found Roof competent to stand trial after a hearing held in November ahead of the guilt phase. Roof represented himself during one week of jury selection in November during which prominent capital defense lawyer David Bruck was appointed standby counsel.

That same defense team filed a motion ahead of the penalty phase arguing that Roof was not competent to represent himself after he revealed at a hearing last week that he would not present any evidence or witnesses.

(Reporting by Harriet McLeod; Editing by Daniel Trotta and Tom Brown)