SPOILER WARNING
The player is first given access to Ultra Warp Ride at the Altar of the Sunne/Altar of the Moone by the Ultra Recon Squad in order to stop Necrozma from stealing Alola's light. As Necrozma had transformed into its Dusk Mane/Dawn Wings form by absorbing Nebby, the player must borrow the Ultra Recon Squad's Lunala/Solgaleo to travel to Ultra Megalopolis, where Necrozma had fled to. In order to arrive at Ultra Megalopolis at this point in the game, the player must enter any white warp hole.
After defeating Ultra Necrozma at Megalo Tower, the Ultra Recon Squad will allow the player to choose to ride on either Solgaleo or Lunala in later uses of Ultra Warp Ride; talking to Phyco/Zossie will allow them to change which Legendary Pokémon they ride, and doing so will return them to Alola. The player can then use the Ultra Wormhole at the Altar of the Sunne/Moone to use Ultra Warp Ride or travel directly to Ultra Megalopolis, and all white warp holes will then lead to Ultra Beasts' homeworlds.
Source