Rare Pokémon can be found by using the new Island Scan feature in Pokémon Ultra Sun and Moon
A new feature in Pokémon Ultra Sun and Moon allows players to capture rare and exciting Pokémon to add to their growing team.
Using the QR Scanner, which is a new in-game feature that can be found in the main menu, you can scan various QR codes of different Pokémon and it adds them to your Pokédex if you haven't seen them before. But you can only scan 10 Pokémon QR codes a day.
After you have scanned 10 QR codes, the game will allow you to initiate an Island Scan, which reveals the trace of a rare Pokémon that otherwise can't be found in the Alola region. Each Pokémon has a specific location depending on the day of the week, so be sure to activate this on the day that the Pokémon you want will appear.