If you’re a prolific writer, you almost have to write in more than one genre. A publisher can only handle so many novels by the same writer in the same genre. Pseudonyms are rampant. Dean Koontz has used at least eleven. Harlan Ellison has used more than two dozen.
If you can write no more than a book or two per year, there will be scant opportunity to switch genres. If, however, you can write three, four, or eight books per year, and many writers do, then switching genres is almost a necesity. Doing so is very common.
I do think it’s s terrible idea to switch around in genres until and unless you first sell in one genre. Switching around too much before this just dilutes effort, makes it take longer to master anything, and can ruin a writer’s chances of success.
But once you can write well enough to sell, then switching around is the norm for prolific writers.