The 21-year-old has played 17 times this season for the Light Blues but the two parties failed to agree terms on a contract extension.
The centre-back is a free agent this coming summer and Hamburg have swooped to tie the player up on a long-term deal.
HSV’s sporting director Johannes Spors said: “David brings in a combination of height, speed, mentality and accountability for the defensive side of the game.
“He is a down-to-earth guy who wants to develop his career and work hard for it.”
Bates originally joined Rangers on a six-month loan from his hometown club Raith Rovers in the summer of 2016. The move was made permanent later in the season and he made his debut towards the end of the campaign, starting in a 0-0 draw at Kilmarnock.
Having fallen down the pecking order due to a combination of injury and the arrival of Bruno Alves and Fabio Cardoso at the beginning of this season, Bates forced himself back into contention and put in a man-of-the-match performance in the 0-0 draw with Celtic before the new year.
He hasn’t played since injuring his ankle as Tom Rogic scored in the most recent Old Firm clash as Brendan Rodgers’ men won 3-2 at Ibrox last month.
Hamburg find themselves in a battle for survival, currently sitting in second last place in the Bundesliga table, five points behind Mainz 05 in the playoff spot and seven short of safety with five games left to play.
They have, however, enjoyed a mini-revival of late, drawing away to Stuttgart before defeating Schalke 3-2 this past weekend.