It depends on all kinds of factors. If any hotel in a general area will do, then anywhere from a month to a few months is good. So you can book for that trip to Paris or Des Moines next winter late next fall and be fine. If you plan to use taxis or the Metro, it doesn't matter whether it's a fifteen minute ride or a twenty, right?
However, if you want a specific hotel, it's worth it to book as early as you know your plans, even if it costs more. The only good hotel where one of our kids went to college was booked two years in advance for graduation weekend. (We never once managed to get a room there.)
Hotels can and do sell out during peak travel seasons or around special events. Only yesterday, a concert we had tickets to announced its rescheduled dates. Within five minutes, the two large hotels in walking distance were sold out, and all the others in the region had jacked up their prices to double to triple the usual rate. (We will be driving 45 minutes after the show ends to reach an affordable hotel.)