This is an unfortunate and undoubtedly embarrassing situation; I'm sorry you had this experience and I hope the remainder of your stay was pleasant. As a hotel guest, you are entitled to receive the services for which you paid, including a room that is private and secure. The laws for what exactly a hotel is responsible for seem to vary by state, and I am not a lawyer so I can't offer legal advice, but as a consumer with years of experience in the customer service industry I think it's reasonable to expect the hotel to offer some sort of concession (perhaps a discount or complimentary services) to make up for the inconvenience.
I would begin by contacting management to report the incident and asking what course of action they will pursue to make amends. You will likely find a list of contact numbers located near the phone in your hotel room, and if you call the front desk and request someone who can help with a customer service issue, they should be able to connect you with the appropriate person. Once you have this person on the phone, explain that the key to your room was also given to another guest, who walked in while you were undressed, and point out that you are both disturbed by the error in security and embarrassed by the violation of privacy. The representative will likely apologize for the incident, and it's possible they will offer some form of compensation or concession to make up for the trouble. If a solution is not presented, try politely asking something similar to "how do you propose to make this situation right, and how can I be sure this won't happen again?"
If the representative of the hotel to whom you speak is not helpful or does not present an acceptable solution, try visiting the hotel's web site and retrieving the number for customer service. This number will likely be in small print at the bottom of the web page, and if you're staying in a major hotel chain (Hilton, Holiday Inn, Best Western, etc.) you can pull this number from the company's main website rather than looking for a specific location. When you speak with a customer service representative, repeat the problem you had with your hotel room and point out that you did not receive adequate customer service from hotel staff regarding this matter. The representative to whom you're now speaking should be able to offer a solution, perhaps in the form of a hotel credit or something similar, and if a concession is not presented, it may be helpful to again ask how they plan to address the problem.
Hotels desire to be known for providing superior service since this can be helpful in increasing business, and bad reviews can be harmful in gaining new customers and in ensuring the return of existing customers. If the hotel does not address this breach of privacy in a way that you deem acceptable, consider leaving detailed reviews on travel accommodations sites such as TripAdvisor or Fodor's, which may then be addressed by management in order to discourage bad publicity. Publicly addressing the issue on the company's social media accounts may also be helpful in gaining some form of recourse, particularly if you have a publicly viewable Twitter or Instagram account.