Upon exiting Diglett‘s Cave, you will be at the eastern segment of the route. Go directly South and enter the building with a grey roof. Make sure you currently have caught at least 10 different species of Pokémon. To check if condition is met, press ‘P’ to open Pokédex and look under the heading ‘Pokédex data’ at the top left. It will show the number of Pokémon you have seen and caught.
Speak with Prof Oak’s Aid and he will give you the HM Flash when you have met the above condition. Then return to Cerulean City and go to the eastern path to Route 9. There are 2 alternative ways to go back to Cerulean City: Either head to Pewter City and go through Mt Moon, or return to Diglett‘s Cave, pass through Vermillion City, and take the Underground Path.