First of all, you did nothing wrong. The hotel failed you. Sometimes hotels run out of space because of clerical errors, guests who overstay, rooms that need repairs, and other reasons that have nothing to do with you.
Usually when a hotel is overbooked, the manager will make arrangements to send you to a nearby property and cover the cost of that room and transportation to get you there. Behind the front desk, that's called "walking" the guest—as in walking them to a different hotel.
Getting walked is annoying and inconvenient, though. Fortunately, there a few things you can do to avoid it.
1) Be a member of the loyalty program. Corporate hotels are much more likely to accommodate a guest if there's a perception that they're loyal.
2) Book directly with the hotel. People who reserve rooms through a third-party website or discount app often have their reservations delivered to the hotel in separate emails from each vendor, so it's easy for your booking to get lost in the shuffle. Worse, if you use one of those sites, some managers might be more likely to consign you to the bottom of the priority list. This is foolish on their part—lots of big spenders still use discount apps to save money or discover new properties—but it can happen.
3) Don't arrive late. Or if you have to, call or email the hotel around lunchtime to let the front desk know you'll be arriving late at night and ask for a note to be made on your account. No-shows happen all the time in the hotel business (some published estimates have the rate as high as 15% of all bookings), so if you arrive too late in the evening, occasionally your room will have been resold on the assumption that you weren't going to turn up.
4) Stay longer. If you're only going to be there for one night, it's easier and cheaper for a hotel to walk you than it would be if you were staying for three nights.
5) Tell them why you're in town. If you were a hotel manager, who would you rather bump: someone who's just sightseeing or someone who's in town for a honeymoon? The better the reason for your trip, the less likely you'll be selected for the inconvenience. If you want to make triple-sure that the management believes you're a serious guest, a few days ahead of arrival you could pay extra to request that a bottle of champagne be ready when you check in.
Walking, take a hike!