The 27-year-old Greek man was certifiably insane at the time of the killing, after which he threw himself from a wall in a suicide attempt, a Hamburg court ruled.
"If necessary, he will spend the rest of his life in the closed facility," Judge Wolfgang Backen said as he handed down his verdict.
"I hope he will never leave the clinic in his life every again," the victim's mother Melissa Keele, who was present at the trial, said after the sentence. "He is a dangerous man."
Police only found out what the 27-year-old Greek engineer had done after he tried to commit suicide by jumping from a height of ten metres at Hamburg Airport last August.
He survived, though critically injured, and police found the victim's papers and a hotel key on him.
Officers then found the body of 23-year-old Texan woman Brittany Keele in the hotel room in the St. Georg district of the northern Germany city. She had bled to death after being stabbed 180 times with a Swiss army knife. Three of the stabs had punctured her lung.
Police also found the tip of one of the Greek's fingers, which he had apparently cut off himself, in her hair.
The judge closed the trial to the public at the request of the defence lawyer, who said her client's delusions were made worse by the presence of more people.
The trial relied heavily on testimony of the mothers of both victim and perpetrator.
The judge commended both women for their courage, and said it was admirable that they had met outside the court to discuss the tragic events. "They both lost a child," he said in his court statement.