It dates back to merchant ships, where staterooms were the rooms reserved for the captain and paying passengers. They were nicer and more comfortable than the crew quarters. In the word stateroom state refers to status aboard the ship. Higher status meant better room.