The prosecutors had said the suspect, who was under the influence of alcohol at the time of the incident on Tuesday afternoon, could be placed in psychiatric care.
But a judge ruled on Wednesday that he should be placed in custody, though no details were given of a possible motive.
The suspect, a native of the quaint city of Trier in Germany's Rhineland-Palatinate state, is accused of five counts of murder and 18 counts of attempted murder, the judge said.
He is accused of tearing through the pedestrian zone in a silver SUV, killing five people including a nine-week-old baby and injuring 18 others, six of them seriously.
The victims also included three women aged 25, 52 and 73 and a 45-year-old man — the father of the baby who was killed.
(article continues below)
See also on The Local:
The suspect was arrested at the scene and police were able to question him but said there were no indications of a religious or political motive.
Hundreds of people gathered on Wednesday morning around Trier's Porta Nigra Roman city gate to pay tribute to the victims, despite coronavirus restrictions.
“Let us maintain this solidarity that I am experiencing here, right now, in the weeks and months to come,” Trier mayor Wolfram Leibe said.
Rhineland-Palatinate state premier Malu Dreyer condemned the “terrible event here in this beautiful city”.
“Nothing, really nothing, can justify this brutal and terrible act,” she said.