There are a lot of factors that go into determining a ship's itinerary. It's not the ship's captain saying, "I think we'll go to Puerto Rico just for a few hours at night that day." Every port has a set number of piers at which the ships can dock. It could be that there is no available docking space the day before or that day, until 3pm. Some governments, like Bermuda, limit the number of cruise ships that can be in port at the same time.
It's probably more a case of Royal Caribbean being told, "The only time we can accommodate this particular ship is 3-10pm. Take it or leave it." It's likely that other Royal Caribbean ships will be docked in Puerto Rico that day; perhaps there is a limit to how many ships from the same cruise line can use up dock space at the same time.
Another consideration are tides. The ships have a window of opportunity for arriving into port and leaving, according to the tides and sea conditions.
I'm sure there are other considerations as well that I'm not aware of or not thinking of. It's not usually a case of some suit at Royal Caribbean saying let's allow the passengers of this ship to be in port just a few hours.