Think of the dative Тому like in the phrasing мне ____ лет. It's saying to "that" five years.