Either are fine to use in terms of natural, native sounding speech. 'When' is generally used first time, but because for 'What,' it includes the qualifier 'is the best time,' then, 'what is the best time to visit' is fine too.
3 กันยายน 2023
2
1
1
"When" means "at what time?" so I would say either
"What is the best time to visit?"
or
"When is it (or 'would it be') best to visit?" (because "what time" is repetitive),
but it is quite all right to say
"When is the best time to visit?"